Implement a browser history navigator backed by a doubly linked list.
Each node holds a URL and two pointers (prev, next). The cursor always
points at the current page. Visiting a new URL appends a node after the
cursor and discards everything forward (just like a real browser).
API
class BrowserHistory {
constructor(homepage) // start on this URL
visit(url) // move forward; drop all forward history
back(steps) // move backward up to `steps` pages; return current URL
forward(steps) // move forward up to `steps` pages; return current URL
}solve(homepage, ops) replays operations and returns the current URL after
every back and forward call (visit produces null in the output).
Example
solve('home.com', [
['visit', 'a.com'],
['visit', 'b.com'],
['back', 1], // → 'a.com'
['back', 1], // → 'home.com'
['forward', 1], // → 'a.com'
['visit', 'c.com'], // → null (b.com is now gone)
['forward', 100], // → 'c.com' (already at end)
['back', 2], // → 'home.com'
])
// output: [null, null, 'a.com', 'home.com', 'a.com', null, 'c.com', 'home.com']Constraints
boundary.
DListNode must carry both prev and next pointers.Sample tests