FastPrepFastPrep
Problem Brief

Repeatedly Add Consecutive Equal Digits

INTERNOA

See the Image Source section at the very bottom of the page for the original problem statement ๐Ÿผ

Imagine you're given a string made entirely of digits, and your goal is to transform it by repeatedly applying a special operation whenever there are consecutive identical digits. Here's how it works: if a number has repeated digits, you replace each group of consecutive digits with their sum. For example, the number "999433" would become "2746" because 9 + 9 + 9 equals 27, and 3 + 3 equals 6. You keep doing this until there are no consecutive digits left. For instance, "44488366664" would first transform to "12163244." Keep applying this process until the string no longer has any repeating digits, and that's your final result. The challenge here is to find an approach that gets this done efficiently, though it doesn't need to be the most optimal one.

๐Ÿฐ Appreciation to Charlotte baby ๐Ÿฐ

1Example 1

Input
number = "999433"
Output
"2746"
Explanation
Because 9 + 9 + 9 = 27 and 3 + 3 = 6

2Example 2

Input
number = "44488366664"
Output
"12163244"
Explanation
Following the same logic mentioned above, you will get --> 12163244

3Example 3

Input
number = "66644319333"
Output
"26328"
Explanation
Imagine youโ€™re given a number with consecutive digits that are the same, and your task is to transform it step by step. Letโ€™s take the number "66644319333." First, you spot the consecutive equal digits: "666," "44," and "333." You replace each group with the sum of its digits: "666" becomes 18, "44" becomes 8, and "333" becomes 9. So, the number now transforms into "1883199." But wait, there are still consecutive equal digits, "88" and "99," so we apply the same process again. This time, "88" becomes 16, and "99" becomes 18, turning the number into "1163118." Once more, there are consecutive digits, "11" and another "11." Summing those gives us "26328," which is the final result, with no more repeats left. So, the final output is "26328."

4Example 4

Input
number = "0044886"
Output
"084"
Explanation
. After one operation, number = "08166". Then it sequentially becomes 08112 P.S. The explanation isn't complete. I'll add more once I find more reliable source :)

Constraints

Limits and guarantees your solution can rely on.

๐Ÿ“๐Ÿ“
public String repeatedlyAddConsecutiveEqualDigits(String number) {
  // write your code here
}
Input

number

"999433"

Output

"2746"

Sign in to submit your solution.