Code Room
CodingMediumcod-g777
Subject Design data structuresLevel Mid–Senior~25 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.