Skip to content

Practice Design Browser History

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1472
LeetCode Problem

Design Browser History

Problem Statement

Implement BrowserHistory(homepage) for one browser tab. visit(url) opens url from the current page and discards all forward history. back(steps) moves backward by at most that many available history entries and returns the resulting URL. forward(steps) moves forward by at most that many available entries and returns the resulting URL. If the requested move exceeds the available history, stop at its end.

Source: Design Browser History on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
["BrowserHistory","visit","visit","visit","back","back","forward","visit","forward","back","back"] [["leetcode.com"],["google.com"],["facebook.com"],["youtube.com"],[1],[1],[1],["linkedin.com"],[2],[2],[7]]
Output
[null,null,null,null,"facebook.com","google.com","facebook.com",null,"linkedin.com","google.com","leetcode.com"]

Constraints

1 <= homepage.length <= 20
1 <= url.length <= 20
1 <= steps <= 100
homepage and url consist of  '.' or lower case English letters.
At most 5000 calls will be made to visit, back, and forward.

Related LeetCode Problems

Practice more problems similar to Design Browser History.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.