Web Browser
Implement a web browser with the following methods:
WebBrowser(String homepage)
constructs a new instance of the browser with starting page ofhomepage
.visit(String page)
visits the sitepage
, clearing all forward history.back(int n)
goes backn
number of steps in history and returns the current page. Note that once you reach thehomepage
, you stay on that page even if you goback
.forward(int n)
goes forwardn
number of steps in history and returns the current page. Note that once you reach the most recent page, you stay on that page even if you goforward
.
Constraints
n ≤ 100,000
wheren
is the number of calls tovisit
,back
andforward
.
https://binarysearch.com/problems/Web-Browser
Examples
Example 1
Input
- methods =
['constructor', 'visit', 'visit', 'visit', 'back', 'forward']
- arguments =
[['wikipedia.org'], ['google.com'], ['stackoverflow.com'], ['github.com'], [2], [1]]
Output
- answer =
[None, None, None, None, 'google.com', 'stackoverflow.com']
Explanation
browser = WebBrowser("wikipedia.org")
browser.visit("google.com")
browser.visit("stackoverflow.com")
browser.visit("github.com")
browser.back(2) == "google.com"
browser.forward(1) == "stackoverflow.com"
Leave a comment