Watch 10 video solutions for Check Balanced String, a easy level problem involving String. This walkthrough by NeetCode has 475,216 views views. Want to try solving it yourself? Practice on FleetCode or read the detailed text solution.
You are given a string num consisting of only digits. A string of digits is called balanced if the sum of the digits at even indices is equal to the sum of digits at odd indices.
Return true if num is balanced, otherwise return false.
Example 1:
Input: num = "1234"
Output: false
Explanation:
1 + 3 == 4, and the sum of digits at odd indices is 2 + 4 == 6.num is not balanced.Example 2:
Input: num = "24123"
Output: true
Explanation:
2 + 1 + 3 == 6, and the sum of digits at odd indices is 4 + 2 == 6.num is balanced.
Constraints:
2 <= num.length <= 100num consists of digits only