Implement Back and Forward Navigation for the Amazon Shopping App
Last updated: November 29, 2026
Quick Overview
Design a navigation history starting at a home page with `visit(url)` (which clears forward history), `back(steps)`, and `forward(steps)`, where back and forward move at most as far as history allows and return the current page.
Amazon
November 29, 20260
0
0 solved
Design a navigation history starting at a home page with `visit(url)` (which clears forward history), `back(steps)`, and `forward(steps)`, where back and forward move at most as far as history allows and return the current page.
A screen question in Amazon's style for frontend or app engineers, framed around in-app navigation between search results, detail pages, and the cart. It checks a clean O(1) design and whether you remember that a new visit discards the forward stack.
What the Interviewer Expects
- Clears forward history on visit
- Clamps back and forward to available history
- Achieves O(1) per step or O(1) per call
- Chooses between two stacks and an array with a pointer, explaining why
- Considers memory caps on long sessions
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you cap history at 50 entries without O(n) shifts?
- How would you persist history across app restarts?
- How would you collapse repeated visits to the same URL?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Start at home. visit moves to a new page and drops everything ahead of the current page. back(k) and forward(k) move up to k steps, clamped to the ends, and return the resulting URL....
High-Level Design
Two stacks (back and forward) work but cost per move. An array plus two indices is simpler and makes every call : cur is the current page and end is the last valid forward page. `visi...