Browser history
Implement browser history. Process ops: ['visit', url] clears all forward history and goes to url; ['back', steps] moves back up to 'steps' pages but not before the first page and returns the current url; ['forward', steps] moves forward up to 'steps' pages but not past the last visited page and returns the current url. The first op is always a 'visit'. Return the list of urls returned by each back/forward op.
Implement
browser_history(ops: list[list]) → list[str]Examples
in
[[["visit","a"],["visit","b"],["visit","c"],["back",1],["back",1],["forward",1],["visit","d"],["forward",2],["back",2]]]out["b","a","b","d","a"]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 20 min
solution.py
InputExpectedGot
[[["visit","a"],["visit","b"],["visit","c"],["back",1],["back",1],["forward",1],["visit","d"],["forward",2],["back",2]]]["b","a","b","d","a"]not run yetsample