We use cookies for site analytics. Accept to help us understand how the site is used. See our Privacy Policy for details.
A medium design problem, graded against 6 test cases (3 of them hidden).
Build a working data structure to an API - LRU caches, rate limiters, and iterators.
Reach for it when you see: "Design a class supporting these operations in O(1)" - an API rather than a single function.
More Designproblems →Model history as a list of urls plus a `current` index. The homepage seeds the list at index 0. `visit` discards any forward entries by truncating to `current + 1`, appends the new url, and advances `current`. `back` and `forward` clamp `current` to the `[0, length - 1]` range so you never run off either end, then return the url at the resulting index.
The full reference solution in every supported language stays in the editor above - reveal it there once you have had a real attempt.
Read off this problem's own test suite, so these are the cases a submission actually has to survive.
These apply to the pattern as a whole, not just this problem.