Problem
Design a class BrowserHistory for a single browser tab.
- BrowserHistory(homepage) opens the tab on homepage.
- visit(url) goes to url from the current page and clears all forward history.
- back(steps) moves back up to steps pages and returns the current URL. If there are fewer pages behind you, it stops at the first page.
- forward(steps) moves forward up to steps pages and returns the current URL, stopping at the last page.
Example 1
h = BrowserHistory("home.com")Example 2
h.visit("a.com"); h.visit("b.com"); h.visit("c.com")Example 3
- Input
- h.back(1)
- Output
- "b.com"
Example 4
- Input
- h.back(1)
- Output
- "a.com"
Example 5
- Input
- h.forward(1)
- Output
- "b.com"
Example 6
h.visit("d.com") (c.com is gone from forward history)Example 7
- Input
- h.forward(2)
- Output
- "d.com"
Example 8
- Input
- h.back(2)
- Output
- "a.com"
Example 9
- Input
- h.back(7)
- Output
- "home.com"
Constraints
1 <= homepage.length, url.length <= 201 <= steps <= 100At most 5000 calls to visit, back, and forward.