Design a browser history system with support for next, prev, and multiple tabs
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2019-11-20
Problem Statement
Design and implement a Browser History Management System that supports navigation (back, forward) and management of multiple browser tabs.
🔶 Functional Requirements
1.Navigation
•Support visit(URL) → adds a new page to the history.
•Support back() → moves to the previous page in history (if available).
•Support forward() → moves to the next page in history (if available).
2.Tab Management
•Support opening a new tab (with its own independent history stack).
•Support closing a tab.
•Switch between tabs.
3.History Persistence (per tab)
•Each tab maintains its own sequence of visited URLs.
•When a new URL is visited after going back, the forward history is cleared (like real browsers).
4.Session Handling
•Track all open tabs and their respective histories.
•Provide current active page per tab.
🔶 Non-Functional Requirements
•Performance: Back/forward navigation should be O(1).
•Memory Management: Should handle large browsing histories efficiently.
•Extensibility: Future support for bookmarks, history search, or cross-device sync.
🔶 Constraints
•A tab must always have at least one active page once a URL is visited.
•Visiting a new URL after going back clears forward history for that tab.
•The system should handle multiple concurrent tabs with independent histories.
🔶 Example Use Case
1.Open Tab 1 → visit google.com → leetcode.com → github.com.
•Current: github.com.
•Back → goes to leetcode.com.
•Forward → goes back to github.com.
•Visit stackoverflow.com after going back → forward history (github.com) is cleared.
2.Open Tab 2 → visit openai.com → chat.openai.com.
•Current: chat.openai.com.
•Closing Tab 2 removes its history.
3.Switching back to Tab 1 still shows its own history state.
👉 In short:
Design a Browser History System that allows visiting URLs, navigating back/forward efficiently, and supports multiple independent tabs, each with its own navigation history.