Design browser history across tabs
Company: Chime
Role: Backend Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Technical Screen
Design a browser-history component.
Start with a single tab and support these operations:
- `visit(url)`: navigate to a new URL from the current page. If the user had gone back earlier, all forward history for that tab is discarded.
- `back(steps)`: move backward up to `steps` pages and return the current URL.
- `forward(steps)`: move forward up to `steps` pages and return the current URL.
- `haveVisited(url)`: return whether this URL has been visited before.
Follow-up:
1. Explain how you would support multiple tabs, where each tab has its own independent back/forward state.
2. Explain how to answer whether a URL has been visited in any tab.
3. Discuss the main data structures, edge cases, and time/space complexity.
Quick Answer: This question evaluates a candidate's ability to design stateful data structures and manage per-tab navigation history, testing competencies in data structures, algorithmic complexity analysis, and system modeling.