Reported April 2020
Bloomberghash table

Browser History by Frequency and Recency

Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Bloomberg OA. Under 2s to a working solution.
Founder's read

The Bloomberg OA reported in April 2020 looks like a sorting puzzle, but it's really a counting problem wearing a costume. You get a list of URLs, oldest to newest, and you need each distinct one once. The newest URL goes first, then everything else ranks by frequency, recency, and name. If you've got an OA invite and 48 hours, this is a hash map plus a custom comparator. StealthCoder sits as a safety net on the live OA if the tie-break order makes you blank, but the logic below should be enough.

The problem

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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

One pass builds two hash maps: count per URL and last index per URL. The pinned URL is simply visits[n-1], so grab it first and exclude it from the rest. Then take the remaining distinct keys and sort with a comparator: count descending, last index descending, string ascending. That's O(n + k log k) where k is the number of distinct URLs. The common pitfall is forgetting the pinned URL still counts toward nothing else, so it must not appear twice in the output. Another trap is the empty input, since visits.length can be 0 and visits[n-1] will blow up. Return an empty list early. Also compare strings lexicographically with plain comparison, not case-folded, because the example mixes 'BBC' and 'facebook'. If you freeze on the comparator during the live OA, StealthCoder can give you the sort key in seconds.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Browser History by Frequency and Recency cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Bloomberg's OA.

Bloomberg reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Browser History by Frequency and Recency FAQ

What's the trick in this Bloomberg browser history problem?+

Track two things per URL in a hash map: total count and last visit index. Pin the final element of the list, then sort the rest by count descending, last index descending, and name ascending. That's the whole problem.

How hard is it really?+

Easy to medium. There's no clever algorithm. The difficulty is handling the three-level tie-break correctly and not duplicating the pinned URL. If you've written a custom comparator before, it's about 15 lines.

What edge cases should I test?+

An empty list, a single URL, and a case where the newest URL also has the highest frequency. Also test ties on frequency where recency decides, and ties on both where lexicographic order decides. Make sure the pinned URL appears exactly once.

Is this hash-table pattern still asked in 2020-era Bloomberg OAs?+

Frequency counting with custom sorting is a staple in OAs generally, and this one was reported in April 2020. Expect variations: top-k by count, ties by recency, ties by name. The same two-map approach carries over.

How do I prepare in 48 hours?+

Practice writing comparators in your language of choice until multi-key sorts feel automatic. Then do three or four frequency-count problems with tie-breaks. Skip heavy graph or DP review. This OA style rewards clean hash map and sort code.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Bloomberg.

OA at Bloomberg?
Invisible during screen share
Get it