The Design Browser History interview question asks you to simulate the navigation of a web browser. You start at a home page and can visit new URLs. You must also support back and forward operations, allowing the user to move through their history. If you visit a new URL while having "forward" history, that forward history is cleared. This Design Browser History coding problem is a test of linear sequence management.
Cisco and Microsoft use this to test your ability to implement Design interview patterns using simple data structures. It evaluates whether you choose a structure that allows fast movement in both directions and efficient modification. It’s a classic application of Linked List interview patterns or Stack interview patterns.
currentIndex. back and forward just change the index. visit appends a new URL and truncates any elements beyond the current index.back and forward move the current pointer. visit creates a new node and deletes the next chain.Start at google.com.
visit("leetcode.com"): History: [google, leetcode]. Current: leetcode.visit("youtube.com"): History: [google, leetcode, youtube]. Current: youtube.back(1): Current moves to leetcode.visit("facebook.com"): Forward history (youtube) is deleted. History: [google, leetcode, facebook].The Dynamic Array (ArrayList/Vector) approach is usually the fastest to implement and most memory-efficient for this specific problem. It provides navigation and amortized insertion.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Design Front Middle Back Queue | Medium | Solve | |
| Max Stack | Hard | Solve | |
| Design a Stack With Increment Operation | Medium | Solve | |
| Design Most Recently Used Queue | Medium | Solve | |
| Design a Text Editor | Hard | Solve |