JuniorString
Check Balanced String
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
falseThe sums at even and odd indices are 4 and 6, so
num is not balanced.Example 2
Input
num = "24123"Output
trueThe sums at even and odd indices are both 6, so
num is balanced.Constraints
- 2 <= num.length <= 100
- num consists of digits only
Asked at 1 companies
Practice questions like this out loud in a mock coding interview with a live AI interviewer. First one free.