Design Browser History
Problem statement
Start a browser on homepage and process commands:
visit url: navigate to url and discard all forward history.back steps: move back up to steps entries and append the resulting URL.forward steps: move forward up to steps entries and append the resulting URL.
Visit commands produce no output. Return results of back and forward commands in order.
Function
browserHistory(homepage: String, operations: String[]) → String[]Examples
Example 1
homepage = "leetcode.com"operations = ["visit google.com","visit facebook.com","visit youtube.com","back 1","back 1","forward 1","visit linkedin.com","forward 2","back 2","back 7"]return = ["facebook.com","google.com","facebook.com","linkedin.com","google.com","leetcode.com"]The LinkedIn visit discards the prior YouTube forward branch.
Constraints
1 <= operations.length <= 10^4.- URLs are nonempty and step counts are positive integers.