Amazon SDE2 - Interview Question - DSA
Anonymous User
972

Came across this question from a recent Amazon SDE-2 loop and thought it’s a great example of where interviewers care way more about trade-offs than just getting "a" working solution.

The Problem: Design a system to navigate browser history. You need to support:

visit(url) — Clears forward history, visits a new URL.

back(steps) — Moves back up to N steps in history.

forward(steps) — Moves forward up to N steps in history.

The Core Trade-offs:

Doubly Linked List: Gives clear dynamic resizing and O(1) node insertion, but moving K steps back/forward takes O(K) traversal time.

Two Stacks (Back & Forward): Easy to reason about during a high-pressure round, but popping and pushing elements across two stacks for multi-step jumps introduces extra operations.

Dynamic Array + Pointer: Gives instant O(1) time lookups for moving K steps, but clearing forward history requires truncating or resizing array boundaries.

If you were sitting in the candidate seat for a 45-minute round, which approach are you choosing, and how would you explain your choice to the interviewer?

Also, how would you handle memory/garbage collection if the forward history gets massive?

Note: I have been indexing fresh, real-world interview loops, compensation data, and DSA questions like this over at BeyondLeet. The goal is to build a platform that focuses on real interview experiences without just giving away canned solutions. Feedback is super welcome!

Comments (4)