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

Question

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.

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.