Friendship String
Problem statement
You are given a string s containing decimal digits. In one operation, choose a digit d, remove it, and insert min(d + 1, 9) at any position.
Perform any number of operations and return the lexicographically smallest string obtainable. Leading zeroes are allowed.
Function
friendshipString(s: String) → StringExamples
Example 1
s = "415863388791991"return = "111445678999999"A digit that has a smaller digit to its right is moved and incremented once, capped at 9. The other digits stay unchanged. Sorting the resulting digits gives 111445678999999.
Constraints
1 <= s.length <= 2 * 10^5scontains only decimal digits.