Code RoomBrowser history
MediumPrep Room Coding #1146

Browser history

CodingAlgorithms & data structuresMid–Senior~20 min

Simulate a browser's history starting at homepage. Replay operations: ["visit", url] navigates to url and clears any forward history; ["back", steps] moves back up to steps pages (stopping at the oldest) and returns the current url; ["forward", steps] moves forward up to steps pages (stopping at the newest) and returns the current url. Return the list of urls produced by every back and forward operation, in order.

Implement
browser_history(homepage: str, ops: list[list]) → list[str]
Examples
in["notebook.com",[["visit","google.com"],["visit","facebook.com"],["visit","youtube.com"],["back",1],["back",1],["forward",1],["visit","linkedin.com"],["forward",2],["back",2],["back",7]]]out["facebook.com","google.com","facebook.com","linkedin.com","google.com","notebook.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 20 min
InputExpectedGot
["notebook.com",[["visit","google.com"],["visit","facebook.com"],["visit","youtube.com"],["back",1],["back",1],["forward",1],["visit","linkedin.com"],["forward",2],["back",2],["back",7]]]["facebook.com","google.com","facebook.com","linkedin.com","google.com","notebook.com"]not run yetsample