FastPrepExpand Decimal Digits into Runs of Ones
Problems/Expand Decimal Digits into Runs of Ones

Expand Decimal Digits into Runs of Ones

ZipRecruiter logoZipRecruiter● EasyNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A ZipRecruiter onsite report describes mixed alphanumeric input, treating each decimal digit separately, and replacing each digit with a run of ones, including the example a5b3de. We supplied how zero works, limits, and a function signature. Our version is about 94% the same as the reported question.

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) → String

Examples

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 <= 100000
  • text contains 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

ZipRecruiter interview experiences

  • ZipRecruiter SWE OA, Level Not Reported: 23 Experiences
  • ZipRecruiter SWE Intern OA Scores: 4 Experiences
  • ZipRecruiter SWE New Grad OA: 9 Experiences
All ZipRecruiter interview questionsSee ZipRecruiter hiring insights
Saved
class Solution {
    public String expandDigitsToOnes(String text) {
        // Write your code here.
    }

}
Checking account…