A ceramics workshop stamps every finished plate with a fixed-length decimal batch tag before it leaves the kiln. A quality inspector calls a tag balanced when the sum of the digits printed in its first half is exactly equal to the sum of the digits printed in its second half; such tags are trusted to have survived the stamping press without a misfire. Given a batch tag, decide whether it is balanced.
A single line containing the batch tag s, a string of decimal digit characters ('0'-'9') of even length.
Print true if the sum of the digits in the first half of s equals the sum of the digits in the second half, and false otherwise.
Example 1
Input
1230
Expected
true
Explanation
The first half is "12" (digit sum 1+2=3) and the second half is "30" (digit sum 3+0=3). The halves match, so the tag is balanced and the output is true.
Example 2
Input
1234
Expected
false
Explanation
The first half is "12" (sum 3) and the second half is "34" (sum 7). Since 3 != 7, the tag is not balanced and the output is false.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →