Capacity-Bounded Browser History
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.