Delimiter-Parsing String Iterator
Updated
Problem statement
Split text at every exact occurrence of the nonempty delimiter and return the fragments in iterator order.
Preserve empty fragments at the beginning, end, or between adjacent delimiters.
Function
iterateFragments(text: String, delimiter: String) → String[]Examples
Example 1
text = "a::b::::c::"delimiter = "::"return = ["a","b","","c",""]Adjacent and trailing delimiters preserve empty fragments.
Example 2
text = "abc"delimiter = "|"return = ["abc"]No delimiter yields one fragment.
Constraints
0 <= text.length <= 100000.1 <= delimiter.length <= 100.
Source note: Author-written prompt excerpt retained for source fidelity.
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
- Run-Length DecodingApple · PHONE SCREENApple 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
- SimpleRDD Word CountDatologyAI · PHONE SCREEN