Check If Digits Are Equal in String After Operations II

You are given a string s consisting of digits. Perform the following operation repeatedly until the string has exactly two digits:

  • For each pair of consecutive digits in s, starting from the first digit, calculate a new digit as the sum of the two digits modulo 10.
  • Replace s with the sequence of newly calculated digits, maintaining the order in which they are computed.

Return true if the final two digits in s are the same; otherwise, return false.

Example 1
Inputs = "3902"
Outputtrue
After the operations, s becomes "11", so the final two digits are the same.
Example 2
Inputs = "34789"
Outputfalse
After the operations, s becomes "48", and since '4' != '8', the output is false.

Constraints

  • 3 <= s.length <= 10^5
  • s consists of only digits.

Asked at 2 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