FunctionRacerProblemsRace

Browser Back and Forward

MediumStacks and queuesPython, JavaScript, TypeScript, Java, C++

A browser starts on the page home. commands is a list of strings applied in order:

Return a list with the page you are on after each back and each forward command, in order. visit commands add nothing to the result.

Example 1

commands ["visit a","visit b","back 1","forward 1","visit c","back 2"]
returns ["a","b","a"]

After home, a, b: back 1 lands on a, forward 1 on b; visiting c makes the history home, a, b, c, and back 2 lands on a.

Example 2

commands ["back 3"]
returns ["home"]

There is only home, so going back 3 stays there.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Stacks and queues problems