Expand Decimal Digits into Runs of Ones
Updated
Problem statement
Scan text from left to right. Replace each decimal digit d with exactly d copies of the character 1. Keep every nondigit character unchanged.
Each digit is interpreted independently, so 0 contributes no characters.
Function
expandDigitsToOnes(text: String) → StringExamples
Example 1
text = "a5b3de"return = "a11111b111de"Each digit expands independently while letters remain in place.
Example 2
text = "x0y2"return = "xy11"Zero contributes an empty run and two contributes two ones.
Constraints
0 <= text.length <= 100000textcontains ASCII letters and decimal digits.
More ZipRecruiter Onsite Interview questions
- Restaurant Vote LeadersPHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2026
- Sliding Window Rate LimiterOA · ONSITE INTERVIEW · Seen Oct 2022
- Sort an Integer Array in Ascending OrderOA · ONSITE INTERVIEW · Seen Apr 2022
- Classify an Alien Dictionary OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2022
- Add Numbers Stored in Four-Digit ChunksONSITE INTERVIEW · Seen Nov 2021
- Add Two Numeric Strings with CarryONSITE INTERVIEW · Seen Nov 2021
- Solve a Sudoku BoardONSITE INTERVIEW · Seen Aug 2021
- Validate a Sudoku BoardONSITE INTERVIEW · Seen Aug 2021
- Iterate Ragged Integer Lists VerticallyONSITE INTERVIEW · Seen May 2017
- Min StackONSITE INTERVIEW · Seen Feb 2017
Similar questions at other companies
- Christmas Tree with N TiersVerily · ONSITE INTERVIEW
- Bounded Word Guess SolverAtlassian · ONSITE INTERVIEWAtlassian interview questions
- Document Edit EventsClickUp · ONSITE INTERVIEW
- Predict Runtime Method DispatchAMD · ONSITE INTERVIEWAMD interview questions
- Basic String Compression with Length GuardNew Relic · PHONE SCREEN · ONSITE INTERVIEW
- Print Sentences as TableAirbnb · PHONE SCREEN · ONSITE INTERVIEWAirbnb interview questions
- Retry with an Attempt LimitOracle · ONSITE INTERVIEWOracle interview questions
- Extract Error Log ContextFlexTrade · ONSITE INTERVIEWFlexTrade interview questions
- Run-Length Encode Consecutive Letter RunsMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions
- String Pattern ReplacementGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions