Design Browser History
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Model a single browser tab's back/forward navigation.
Implement:
- BrowserHistory(homepage) opens the tab on homepage.
- visit(url) navigates to url from the current page. This **discards all forward history**.
- back(steps) moves back up to steps pages (stopping at the oldest page) and returns the current URL afterwards.
- forward(steps) moves forward up to steps pages (stopping at the newest page) and returns the current URL afterwards.
Visiting a URL equal to the current page still adds a new entry. Aim for O(1) per operation (amortized for visit).
Examples
Constraints
- 1 <= homepage.length, url.length <= 20
- 1 <= steps <= 100
- URLs contain lowercase letters, digits and `.`
- At most 5000 calls in total.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.