Friendship String
Updated
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.
More Rubrik interview questions
- Colored Rooted TreeONSITE INTERVIEW · Seen Nov 2026
- Delete and Freeze GameOA · Seen Nov 2026
- Delete K Subsets for Maximum ScoreOA · Seen Nov 2026
- Distribute Elements Into Two Arrays IIOA · Seen Nov 2026
- Minimum Replacements to Sort the ArrayOA · Seen Nov 2026
- All Balanced Strings from Minimum Parenthesis InsertionsONSITE INTERVIEW · Seen Nov 2026
- Insert into a Left-Complete Binary TreeONSITE INTERVIEW · Seen Oct 2026
- Thread-Safe Request Counts by AttributeONSITE INTERVIEW · Seen Oct 2026
- Minimum Swaps To Binary PalindromeOA · Seen Apr 2026
- Get Minimum OperationsOA · Seen Nov 2024
Similar questions at other companies
- Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- Return Exact Cash Register ChangeBank of America · OABank of America interview questions
- Largest Binary Number by ConcatenationAdobe · OAAdobe interview questions
- Maximize Palindromic WordsSquarepoint Capital · OASquarepoint Capital interview questions
- Swap Parity (Data Scientist / Analytics :)JP Morgan Chase · OAJP Morgan Chase interview questions
- Swap ParityPalantir · OAPalantir interview questions
- Join Numbers into the Largest ValueExpedia · ONSITE INTERVIEWExpedia interview questions
- Hiking Club Fastest PaceInfosys · OAInfosys interview questions
- Maximum String OperationsMicrosoft · OAMicrosoft interview questions
- Minimum No-Repeat Segments After One Character RemovalSalesforce · OASalesforce interview questions