15% off all plans & roadmaps Use code
See plansLeetCode 900 · Solution & editorial
We can use run-length encoding (i.e., RLE) to encode a sequence of integers. In a run-length encoded array of even length encoding (0-indexed), for all even i, encoding[i] tells us the number of times that the non-negative integer value encoding[i + 1] is repeated in the sequence.
RLE Iterator is a Design Patterns problem, in the Design (General/Specific) subpattern. The pattern covers tries, LRU/LFU cache, and data structure design
Design and implement data structures: LRU cache, LFU cache, HashMap, and specialized structures.
The reference solution runs in O(L) time and O(L) space.
RLE Iterator has been reported in interviews at Google.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
RLE Iterator is a Design Patterns problem, in the Design (General/Specific) subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.