Browser History by Frequency and Recency
Problem statement
visits lists URLs from oldest to newest. Return each distinct URL once.
Pin the most recently visited URL first. Sort all remaining URLs by descending visit frequency, then descending most-recent visit index, then lexicographically.
Function
rankBrowserHistory(visits: String[]) → String[]Examples
Example 1
visits = ["BBC","BBC","Google","facebook"]return = ["facebook","BBC","Google"]facebook is newest and pinned; BBC then outranks Google by frequency.
Constraints
0 <= visits.length <= 10^5.