01 · Question
Extend Current URL with forward(k), which reverses back navigation up to k times. Forward beyond the newest reachable page does nothing. Every go action clears forward history, even when revisiting the same URL. The first action is go; back/forward counts are positive.
Example: go A, go B, back 1, forward 1, back 3, go C, forward 3 → C.
02 · Analysis
History's top is current; forward's top is the next page that can be restored. On back, move the history top to forward, keeping one page. On forward, transfer in the opposite direction. On go, push the new URL and clear forward.
Two-stack implementation: O(n + M) time and O(n) space, for n actions and M actual page transfers. Unlike back-only navigation, the same pages can move repeatedly; M may be quadratic in n. Clearing forward also has a cost, but each entry can be discarded only once per visit. An alternative history array plus cursor can clamp multi-step back/forward using index arithmetic.