Design Browser History
MediumLinked List
Decode it first. Clues, constraints, pattern and plan before any code.Design a class BrowserHistory for a single browser tab.
BrowserHistory(homepage)opens the tab onhomepage.visit(url)goes tourlfrom the current page and clears all forward history.back(steps)moves back up tostepspages and returns the current URL. If there are fewer pages behind you, it stops at the first page.forward(steps)moves forward up tostepspages and returns the current URL, stopping at the last page.
h = BrowserHistory("home.com")
h.visit("a.com"); h.visit("b.com"); h.visit("c.com")
h.back(1) → "b.com"
h.back(1) → "a.com"
h.forward(1) → "b.com"
h.visit("d.com") (c.com is gone from forward history)
h.forward(2) → "d.com"
h.back(2) → "a.com"
h.back(7) → "home.com"Constraints
1 <= homepage.length, url.length <= 201 <= steps <= 100- At most
5000calls tovisit,back, andforward.