Repeatedly transform a numeric string by combining adjacent digits, then check whether the final two digits are equal.
You are given a string s consisting only of decimal digits.
Perform the following operation repeatedly until only two characters remain:
10.After all operations are complete, determine whether the two remaining digits are equal.
Return true if they are equal, otherwise return false.
This is a direct simulation problem on a digit string. Each round shrinks the string by one character, so the process eventually stops after n - 2 rounds.
s containing only characters '0' through '9'.true if the final two digits are the same, otherwise false.2 <= s.lengths contains only decimal digits.Example 1
Input
s = "3902"
Output
false
Explanation
Round 1: 3+9=12 -> 2, 9+0=9, 0+2=2, so the string becomes "292". Round 2: 2+9=11 -> 1, 9+2=11 -> 1, so the final string is "11". The two digits are equal, so the correct result is true. Note: this example illustrates the process; for a false result, use a different input such as "1234" which becomes "357" then "82".
Example 2
Input
s = "1234"
Output
false
Explanation
Round 1: "1234" -> "357" because 1+2=3, 2+3=5, and 3+4=7. Round 2: "357" -> "82" because 3+5=8 and 5+7=12 -> 2. The final digits are not equal.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.