Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Design Browser History

Medium

Topics
ArrayLinked ListStackDesign

You have a browser with one tab starting on a homepage. Implement BrowserHistory(homepage), visit(url) (visits url from the current page and clears all forward history), back(steps) (move back up to steps pages, return the current url), and forward(steps) (move forward up to steps pages, return the current url).

Example 1

Input:  operations = ["BrowserHistory","visit","visit","visit","back","back","forward","visit","forward","back","back"], values = [["leetcode"],["google"],["facebook"],["youtube"],[1],[1],[1],["linkedin"],[2],[2],[7]]
Output: [null,null,null,null,facebook,google,facebook,null,linkedin,google,leetcode]

Constraints

  • 1 <= homepage.length, url.length <= 20
  • 1 <= steps <= 100
  • At most 5000 calls.
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access