Run-Length Decoding
Updated
Problem statement
Given a run-length encoded string encoded, return the decoded string.
In encoded, each lowercase English letter may be followed by a positive decimal count, which can have several digits. A letter with no count has a count of 1. Repeat each letter by its count and join the results in order. For example, a5b3c decodes to aaaaabbbc. The empty string decodes to the empty string.
Function
decodeRuns(encoded: String) → StringExamples
Example 1
encoded = "a5b3c"return = "aaaaabbbc"Each count applies to the letter right before it, so a and b repeat that many times. c has no count, so it appears once.
Example 2
encoded = ""return = ""An empty encoded decodes to an empty string.
Example 3
encoded = "x12yz2"return = "xxxxxxxxxxxxyzz"All digits after x form one count, so x repeats that many times. y has no count and appears once, and z repeats by its own count.
Constraints
- The input is valid and contains only lowercase English letters and decimal digits.
- Every count is positive, has no leading zero, and is at most
4096. 0 <= encoded.length <= 4096.- The decoded output has at most
4096characters.
More Apple Phone Screen questions
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Topological OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Subarray Product Less Than KPHONE SCREEN · Seen Nov 2026
- Evaluate DivisionPHONE SCREEN · Seen Nov 2026
- Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
- Validate a BST with a Custom ComparisonPHONE SCREEN · Seen Nov 2026
- Design a Food Rating SystemPHONE SCREEN · Seen Oct 2026
- Days Until Poisoned Plants StabilizePHONE SCREEN · Seen Oct 2026
- Capture Surrounded Regions with Union-FindPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Search and Format ContactsAdyen · PHONE SCREENAdyen interview questions
- Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
- Portfolio Valuation, Part 1Stripe · PHONE SCREENStripe interview questions
- Format a Signed Integer with CommasHudson River Trading · PHONE SCREENHudson River Trading interview questions
- Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
- Trace Pointer Rebinding and Pointee UpdatesArista Networks · PHONE SCREENArista Networks interview questions
- Match a Variadic Function SignatureConfluent · PHONE SCREENConfluent interview questions
- Decode and Store StringsAirbnb · PHONE SCREENAirbnb interview questions
- Delimiter-Parsing String Iteratoramo · PHONE SCREEN
- SimpleRDD Word CountDatologyAI · PHONE SCREEN
Apple interview experiences
- Apple SWE Phone Screen: Subarray Products: 1 Experience
- Apple New Grad SWE Java, Coding and Manager Rounds: 1 Experience
- Apple AI Coding and Related Interviews: 17 Experiences
- Apple India SWE New Grad Interviews: 5 Experiences
- Apple New Grad SWE Phone Screens: 12 Experiences (Part 3 of 3)
- Apple New Grad SWE and Embedded: 16 Experiences (Part 2 of 3)