Browser history navigation
Implement browser history starting at a homepage URL. Operations: ['visit', url] pushes a new page and clears all forward history; ['back', steps] moves back up to `steps` pages (stopping at the oldest); ['forward', steps] moves forward up to `steps` pages (stopping at the newest). 'back' and 'forward' return the current URL after moving. Given the homepage and an op list, return the list of URLs returned by each 'back'/'forward' op.
Implement
browser_history(homepage: str, ops: list[list]) → list[str]Examples
in
["a.com",[["visit","b.com"],["visit","c.com"],["back",1],["back",1],["forward",1],["visit","d.com"],["forward",2],["back",2],["back",7]]]out["b.com","a.com","b.com","d.com","a.com","a.com"]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 25 min
solution.py
InputExpectedGot
["a.com",[["visit","b.com"],["visit","c.com"],["back",1],["back",1],["forward",1],["visit","d.com"],["forward",2],["back",2],["back",7]]]["b.com","a.com","b.com","d.com","a.com","a.com"]not run yetsample