ChimeCodingFree preview
Design Browser History (LC 1472)
Candidates confirm it is LC 1472 unchanged: visit / back(steps) / forward(steps) on a single history. Follow-ups add haveVisited(url), then multi-tab support, then a multi-user system.
SWE
data-structure
stack
hashmap
medium
Frequency
Low
Last asked
2026-03-13
Stage
phone-screen
Problem
Candidates confirm the phone-screen prompt is LC 1472 (Design Browser History) unchanged. Implement a single-tab browser history:
BrowserHistory(homepage): start onhomepage.visit(url): navigate tourlfrom the current page and clear all forward history.back(steps): move back up tostepspages and return the current URL; stop at the oldest page.forward(steps): move forward up tostepspages and return the current URL; stop at the newest page.
After the base class works, the interviewer extends the design (see Follow-ups).
Follow-ups
Add
haveVisited(url): report whether a URL has ever been visited in this history.Support multiple tabs, each with its own back / forward history.
Extend to a multi-user system, where each user has independent history.
Preparation
- Implement LC 1472 twice: once with two stacks, once with an array plus a current-index pointer that truncates on
visit. Compare the cost ofback/forwardin each. - Add
haveVisitedon top of your preferred version, and decide whether pages dropped by a latervisitshould still count as visited. Say that choice out loud in the interview. - Refactor the class so histories are keyed by tab id, then by
(user, tab), without duplicating the navigation logic.
Was this article helpful?
Comments
Sign in to join the discussion
Loading...
