Lock in full 90-day FAANG roadmap access before Jan 14, 2026.
⌘K
Design Compressed String Iterator - Easy DSA Problem | Thita.ai
Design Compressed String Iterator
Difficulty: Easy
Category: DSA
Topics: Array, String, Design, Iterator
Asked at: Google, Amazon
You are given a compressed string `compressedString`, where each group consists of a **single uppercase or lowercase letter** followed by a **positive integer** representing the number of times that letter appears consecutively in the original string. For example, the compressed string `"a2b3"` represents the uncompressed string `"aabbb"`.
Design a class `StringIterator` that supports the following operations:
- `next()`: Returns the next character in the uncompressed string as a string. If there are no more characters to return, returns a single space character `" "`.
- `hasNext()`: Returns _true_ if there are more characters to be iterated, or _false_ otherwise.
Implement the `StringIterator` class with the above methods to efficiently iterate through the uncompressed string without decompressing the entire string into memory.