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

Practice questions like this out loud in a mock coding interview with a live AI interviewer. First one free.

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, what to keep, what's wrong, and the complexity of your solution.

Sign in to evaluate