Latest Top 100 News Stories
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Sorting 10^5 stories sounds trivial until you picture a brute-force pass that rescans the whole list 100 times. Bloomberg reported this one in May 2018, and it's a top-K selection problem dressed up as a news feed. You get story IDs, timestamps, and need the 100 newest, with ties broken by the smaller ID. The pattern is greedy selection over a sorted order, or a bounded heap if you want to be fancy. If you blank during the live OA, StealthCoder runs invisibly on your desktop and gives you a working solution as a safety net. Know the comparator and you're done in ten minutes.
The problem
storyIds[i] identifies a unique story whose latest history timestamp is updatedAt[i]. Return up to 100 IDs ordered by descending timestamp, breaking ties by lexicographically smaller ID. Function latestStories(storyIds: String[], updatedAt: long[]) → String[] Examples Example 1 storyIds = ["b","a","c"] updatedAt = [5,5,7] return = ["c","a","b"] c is newest; a and b tie and sort by ID. Constraints Arrays have equal length. IDs are unique. At most 10^5 stories.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is the comparator. Order by updatedAt descending, then by ID ascending. Zip the two arrays into pairs, sort with that comparator, and take the first min(100, n). That's O(n log n), which is fine for 10^5. The tighter option is a size-100 heap, giving O(n log 100), but it's not required. The common pitfall is the tie-break. Candidates sort by timestamp and forget IDs, or sort IDs descending by accident. Another trap is using int for timestamps when the signature says long. Also handle n below 100 so you don't slice out of bounds. And compare IDs as strings, so "10" comes before "9". That's what lexicographic means here. If you freeze on the comparator syntax in your language, StealthCoder is the hedge in the live OA, but the logic itself is short.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Latest Top 100 News Stories 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 would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Bloomberg's OA.
Bloomberg reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Latest Top 100 News Stories FAQ
How hard is the Bloomberg Latest Top 100 News Stories question really?+
Easy to medium. There's no deep algorithm. It's a sort with a two-key comparator plus a cap at 100. Most of the risk is sloppy details: tie-breaking direction, string comparison, and fewer than 100 stories. Solid candidates finish it quickly.
What's the trick to solving it?+
Pair each ID with its timestamp, then sort by timestamp descending and ID ascending. Return the first 100 IDs. The tie-break is the only real catch. The example with a and b both at 5 shows it: a comes before b.
Do I need a heap, or is a plain sort fine?+
A plain sort is fine. With at most 10^5 stories, O(n log n) runs comfortably. A min-heap of size 100 is a nice optimization you can mention, but it adds code and bug risk. Pick the sort unless the interviewer asks for better.
What edge cases should I test?+
Test fewer than 100 stories, exactly 100, and more than 100. Test all timestamps equal so only IDs decide the order. Test IDs like "10" and "9" to confirm lexicographic string comparison. Test a single story and large timestamp values that need long.
How do I prepare for this in 48 hours?+
Write the comparator-based sort in your language of choice until it's automatic. Then do the heap variant once. Practice a few top-K problems with custom tie-breaks. This pattern shows up often, so the repetition carries over to similar OA questions.