FastPrepFastPrep
Problem Brief

Sum Consecutive Identical Digits

FULLTIMEOA

Given a string of digits, repeatedly sum any consecutive identical digits until there are no more consecutive duplicates.

For example:

Input: 99823

  • 99 becomes 18 → 18823
  • 88 becomes 16 → 11623
  • 11 becomes 2 → 2623
Now there are no more consecutive identical digits, so output the final result: 2623.

Function Description

Complete the function sumConsecutiveIdenticalDigits in the editor.

sumConsecutiveIdenticalDigits has the following parameter:

  1. String digits: a string of digits

Returns

String: the final string after summing all consecutive identical digits

1Example 1

Input
digits = "99823"
Output
"2623"
Explanation

  • 99 becomes 18 → 18823
  • 88 becomes 16 → 11623
  • 11 becomes 2 → 2623
Now there are no more consecutive identical digits, so output the final result: 2623.

public String sumConsecutiveIdenticalDigits(String digits) {
  // write your code here
}
Input

digits

"99823"

Output

"2623"

Sign in to submit your solution.