Unique Reverse-Recency Browser History
Problem statement
A browser receives the URLs in visits from oldest to newest. Return the final history from newest to oldest.
Each URL must appear at most once. Revisiting a URL removes its earlier position and makes it the newest history entry.
Function
uniqueBrowserHistory(visits: String[]) → String[]Examples
Example 1
visits = ["www.google.com","www.bing.com","www.facebook.com","www.google.com","www.bloomberg.com"]return = ["www.bloomberg.com","www.google.com","www.facebook.com","www.bing.com"]The second Google visit replaces its older position and becomes newer than Facebook and Bing.
Example 2
visits = ["a","b","a","b"]return = ["b","a"]The last occurrence of each URL determines its recency.
Constraints
0 <= visits.length <= 10^5.- Each URL is a nonempty case-sensitive string.