Design Compressed String Iterator
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
A compressed string is a sequence of letter-count pairs: each English letter is immediately followed by a positive decimal count of how many times it repeats. For example "a2B10" stands for two as followed by ten Bs. Counts can have several digits and can be very large.
Implement StringIterator(compressedString):
- next() returns the next character of the uncompressed string. If every character has already been returned, it returns a single space " ".
- hasNext() returns true if at least one character has not been returned yet.
Do not expand the string; counts may be as large as 10^9.
Examples
Constraints
- 1 <= compressedString.length <= 1000
- `compressedString` alternates an English letter and a count with 1 <= count <= 10^9
- At most 100 calls to `next` and `hasNext`
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.