Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Browser History With Overwrite

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Browser History With Overwrite. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Implement browser history navigation for a Chime web surface. The history starts with a homepage, and each action changes the current page or navigates through existing history.

A visit action opens a new URL. When this happens, every page currently reachable through back is discarded. A back action moves backward by up to steps pages, stopping at the oldest retained page. A forward action moves forward by up to steps pages, stopping at the newest retained page.

Return the current URL after every action, in order.

Formal Specification

Implement browser_history(homepage, actions):

  • homepage is a non-empty string.
  • actions is a list of commands. Each command is either ['visit', url], ['back', steps], or ['forward', steps].
  • Return a list of strings containing the current URL after each command.
  • steps is a positive integer for navigation commands.

Constraints

  • 1 <= len(actions) <= 10^5
  • URLs are non-empty strings of length at most 200
  • 1 <= steps <= 10^9
  • Each command is valid and formatted as specified

Function Signature

def browser_history(homepage, actions):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output