This question evaluates a candidate's ability to design stateful data structures and manage per-tab navigation history, testing competencies in data structures, algorithmic complexity analysis, and system modeling.
Design a browser-history component.
Start with a single tab and support these operations:
visit(url)
: navigate to a new URL from the current page. If the user had gone back earlier, all forward history for that tab is discarded.
back(steps)
: move backward up to
steps
pages and return the current URL.
forward(steps)
: move forward up to
steps
pages and return the current URL.
haveVisited(url)
: return whether this URL has been visited before.
Follow-up: