
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Use two stacks: one for back history, and one for forward history. You can simulate the functions by popping an element from one stack and pushing it into the other.
Can you improve program runtime by using a different data structure?