- Популярные видео
- Авто
- Видео-блоги
- ДТП, аварии
- Для маленьких
- Еда, напитки
- Животные
- Закон и право
- Знаменитости
- Игры
- Искусство
- Комедии
- Красота, мода
- Кулинария, рецепты
- Люди
- Мото
- Музыка
- Мультфильмы
- Наука, технологии
- Новости
- Образование
- Политика
- Праздники
- Приколы
- Природа
- Происшествия
- Путешествия
- Развлечения
- Ржач
- Семья
- Сериалы
- Спорт
- Стиль жизни
- ТВ передачи
- Танцы
- Технологии
- Товары
- Ужасы
- Фильмы
- Шоу-бизнес
- Юмор
LeetCode 3340 - Check Balanced String | Prefix Sum Logic | C++ Full Solution
📌 Problem Statement:
You are given a string num consisting of digits only.
Return true if the sum of digits at even indices is equal to the sum of digits at odd indices. Otherwise, return false.
🧩 What You'll Learn:
✔ Traversing strings efficiently
✔ Difference between even and odd indices
✔ Digit to integer conversion in C++
✔ Simple prefix sum style logic
✔ Time Complexity: O(n)
✔ Space Complexity: O(1)
🛠️ Approach - Step by Step:
STEP 1 → Initialize evenSum and oddSum as 0
STEP 2 → Traverse each character of the string
STEP 3 → Convert character digit into integer value
STEP 4 → If index is even, add digit to evenSum
STEP 5 → Otherwise add digit to oddSum
STEP 6 → Compare both sums and return result
💡 Example:
Input:
num = "1234"
Even indices:
1 + 3 = 4
Odd indices:
2 + 4 = 6
Since 4 is not equal to 6 → Answer is false
⏱️ Timestamps:
0:00 - Problem Statement
1:00 - Understanding Even & Odd Indices
2:30 - Digit Conversion Logic
4:00 - C++ Code Walkthrough
6:00 - Dry Run Example
7:30 - Complexity Analysis
💻 Difficulty: Easy
🏷️ Topics: String, Math, Simulation
📢 LIKE 👍 SHARE 🔗 SUBSCRIBE 🔔 for daily LeetCode solutions!
#LeetCode #LeetCode3340 #BalancedString #CPlusPlus #DSA #CodingInterview #Strings
Видео LeetCode 3340 - Check Balanced String | Prefix Sum Logic | C++ Full Solution канала JALAK PALAN
You are given a string num consisting of digits only.
Return true if the sum of digits at even indices is equal to the sum of digits at odd indices. Otherwise, return false.
🧩 What You'll Learn:
✔ Traversing strings efficiently
✔ Difference between even and odd indices
✔ Digit to integer conversion in C++
✔ Simple prefix sum style logic
✔ Time Complexity: O(n)
✔ Space Complexity: O(1)
🛠️ Approach - Step by Step:
STEP 1 → Initialize evenSum and oddSum as 0
STEP 2 → Traverse each character of the string
STEP 3 → Convert character digit into integer value
STEP 4 → If index is even, add digit to evenSum
STEP 5 → Otherwise add digit to oddSum
STEP 6 → Compare both sums and return result
💡 Example:
Input:
num = "1234"
Even indices:
1 + 3 = 4
Odd indices:
2 + 4 = 6
Since 4 is not equal to 6 → Answer is false
⏱️ Timestamps:
0:00 - Problem Statement
1:00 - Understanding Even & Odd Indices
2:30 - Digit Conversion Logic
4:00 - C++ Code Walkthrough
6:00 - Dry Run Example
7:30 - Complexity Analysis
💻 Difficulty: Easy
🏷️ Topics: String, Math, Simulation
📢 LIKE 👍 SHARE 🔗 SUBSCRIBE 🔔 for daily LeetCode solutions!
#LeetCode #LeetCode3340 #BalancedString #CPlusPlus #DSA #CodingInterview #Strings
Видео LeetCode 3340 - Check Balanced String | Prefix Sum Logic | C++ Full Solution канала JALAK PALAN
Комментарии отсутствуют
Информация о видео
15 мая 2026 г. 9:41:07
00:05:02
Другие видео канала




















