Check If Digits Are Equal in String After Operations II - Problem
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.
Input & Output
Example 1 — Basic Reduction
$
Input:
s = "1234"
›
Output:
false
💡 Note:
Step 1: "1234" → "357" (1+2=3, 2+3=5, 3+4=7). Step 2: "357" → "82" (3+5=8, 5+7=12→2). Final: 8 ≠ 2, so return false.
Example 2 — Equal Final Digits
$
Input:
s = "808"
›
Output:
true
💡 Note:
Step 1: "808" → "88" (8+0=8, 0+8=8). Final: 8 = 8, so return true.
Example 3 — Already Two Digits
$
Input:
s = "11"
›
Output:
true
💡 Note:
String already has 2 digits: 1 = 1, so return true.
Constraints
- 2 ≤ s.length ≤ 1000
- s consists of digits only
Visualization
Tap to expand
Understanding the Visualization
1
Input
String of digits to be reduced
2
Reduction
Iteratively combine adjacent digits
3
Comparison
Check if final two digits are equal
Key Takeaway
🎯 Key Insight: The reduction follows Pascal's triangle pattern - each original digit contributes to the final result with a predictable coefficient weight.
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code