FastPrepCapacity-Bounded Browser History

Capacity-Bounded Browser History

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREEN
Learn

Problem statement

Process parallel operations and urls for a browser history of at most capacity distinct URLs.

  • visit: remove the URL's older position if present, then make it most recent. If over capacity, evict the least recent URL.
  • clear: remove every URL; its matching urls value is ignored.

Return final distinct URLs from least recent to most recent.

Function

finalBoundedHistory(operations: String[], urls: String[], capacity: int) → String[]

Examples

Example 1

operations = ["visit","visit","visit","visit"]urls = ["a","b","a","c"]capacity = 2return = ["a","c"]

Revisiting a makes it newest; visiting c then evicts b.

Constraints

  • Arrays have equal length.
  • 0 <= capacity <= 10^5.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public String[] finalBoundedHistory(String[] operations, String[] urls, int capacity) {
  // Write your code here.
}
operations["visit","visit","visit","visit"]
urls["a","b","a","c"]
capacity2
expected["a", "c"]
Checking account…