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
Inputnum = "1234"
Outputfalse
The sums at even and odd indices are 4 and 6, so num is not balanced.
Example 2
Inputnum = "24123"
Outputtrue
The 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

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate