Browser History Operations
Updated
Problem statement
Implement the history of one browser tab, starting at homepage. Process the operations in actions in order. The entries at the same index in pages and steps give each operation’s arguments.
For this exercise, assume the operations have these rules:
visit: visitpages[i]. Discard all forward history, then add the new page after the current entry. Visiting the same identifier again creates a separate history entry.back: move backward by up tosteps[i]entries. Stop at the earliest entry if fewer are available.forward: move forward by up tosteps[i]entries. Stop at the latest entry if fewer are available.
Return the current page after every operation, including visits and operations that cannot move. Treat each page identifier as a string label. Do not interpret its contents, and treat uppercase and lowercase letters as different. An empty operation list returns an empty array.
Function
browserHistory(homepage: String, actions: String[], pages: String[], steps: int[]) → String[]Examples
Example 1
homepage = "home"actions = ["visit","visit","back","visit","forward","back","forward"]pages = ["b","c","","d","","",""]steps = [0,0,1,0,1,10,2]return = ["b","c","b","d","d","home","d"]After returning to b, visiting d removes c from forward history. Large back movement stops at home.
Example 2
homepage = "home"actions = []pages = []steps = []return = []No operations produce no output entries.
Example 3
homepage = "h"actions = ["visit","visit","back","back","forward"]pages = ["a","a","","",""]steps = [0,0,1,1,2]return = ["a","a","a","h","a"]The two visits to a create separate entries. Two one-step back operations are needed to reach h.
Constraints
0 <= actions.length <= 200, andpages.length = steps.length = actions.length.- Each action is exactly
visit,back, orforward. homepageand each visited page contain1to60characters. Allowed characters are English letters, digits, period, slash, colon, underscore and hyphen.- For a visit,
pages[i]is the visited identifier andsteps[i] = 0. - For back or forward,
pages[i]is empty and0 <= steps[i] <= 10^9.
More Roblox Onsite Interview questions
- Most Frequent Call Path From Function Trace LogsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Search Autocomplete SystemPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Candy Crush Grid Matching and GravityPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Topological Sort with Secondary OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Most Frequent Call Stack Per ThreadPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Count and Score Distinct Hat AssignmentsONSITE INTERVIEW · Seen Sep 2026
- Rate Limiter Sliding Window With Per-Entity LimitsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Most Frequent Call Path in Interleaved LogsONSITE INTERVIEW · Seen Aug 2026
- Grid Pathfinding with Obstacles (DFS)PHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2026
- Maximize Distance to Closest Person — Return the SeatONSITE INTERVIEW · Seen Jun 2026
Similar questions at other companies
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Fountain SafetyGoogle · ONSITE INTERVIEWGoogle interview questions
- Trace Events from Stable Whole-Stack StatesAnthropic · ONSITE INTERVIEWAnthropic interview questions
- Surviving Balls after Directional CollisionsSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Render a Comment HierarchyAmazon · ONSITE INTERVIEW
- Asteroid CollisionAdobe · ONSITE INTERVIEWAdobe interview questions
- Asteroid CollisionZscaler · ONSITE INTERVIEWZscaler interview questions
- Asteroid CollisionBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Exclusive Time of FunctionsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Implement Stack Push and Pop OperationsLSEG · ONSITE INTERVIEWLSEG interview questions