FastPrepBrowser History Operations

Browser History Operations

Roblox logoRoblox● MediumNEW GRADONSITE INTERVIEW
Learn

Problem statement

Implement the history of one browser tab, starting at homepage. Process the operations in actions in order. The parallel arrays pages and steps supply each operation’s arguments.

For this exercise, assume the operations have these rules:

  • visit: visit pages[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 to steps[i] entries. Stop at the earliest entry if fewer are available.
  • forward: move forward by up to steps[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 page identifiers as opaque, case-sensitive strings. 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, and pages.length = steps.length = actions.length.
  • Each action is exactly visit, back, or forward.
  • homepage and each visited page contain 1 to 60 characters. Allowed characters are English letters, digits, period, slash, colon, underscore and hyphen.
  • For a visit, pages[i] is the visited identifier and steps[i] = 0.
  • For back or forward, pages[i] is empty and 0 <= steps[i] <= 10^9.

More Roblox problems

See Roblox hiring insights
public String[] browserHistory(String homepage, String[] actions, String[] pages, int[] steps) {
    // write your code here
}
homepage"home"
actions["visit","visit","back","visit","forward","back","forward"]
pages["b","c","","d","","",""]
steps[0,0,1,0,1,10,2]
expected["b", "c", "b", "d", "d", "home", "d"]
Checking account…