Print Unique Numbers
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The usual way to lose points on Bloomberg's Print Unique Numbers is to reach for a sort or a plain set and wreck the order of first appearance. This one was reported in July 2020. It's a dedupe problem with a catch: keep each integer once, in the order it first showed up. It's a hash-table question at heart, and it's easy if you stay calm. If you freeze during the OA, StealthCoder runs invisibly on your desktop as a safety net and gives you the solution live. Know the trick first and you probably won't need it.
The problem
Return each distinct integer from nums exactly once, preserving the order of its first appearance. Function uniqueNumbers(nums: int[]) → int[] Examples Example 1 nums = [4,1,4,7,1,9] return = [4,1,7,9] Later copies of 4 and 1 are skipped. Constraints 0 <= nums.length <= 2 * 10^5.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is one pass with a hash set. Walk nums left to right. If the value isn't in the set, add it to the set and append it to the result. If it is, skip it. That's O(n) time and O(n) space, which matters because nums can reach 2 * 10^5 elements. The classic mistake is sorting first, which breaks first-appearance order and costs O(n log n). The second mistake is using a list for membership checks, which turns the solution into O(n^2) and times out at the upper bound. Also handle the empty array and return an empty array. Python's dict.fromkeys also works since dicts keep insertion order, but the set plus result list is clearer to explain. If your mind goes blank mid-assessment, StealthCoder is the hedge that surfaces this pattern in seconds.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Print Unique Numbers 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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Bloomberg's OA.
Bloomberg reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Print Unique Numbers FAQ
How hard is Print Unique Numbers really?+
It's easy. One pass, one set, one output list. The only thing that trips people is order. If you remember that first appearance must be preserved, the solution is about six lines. Most of the risk is overthinking it or reaching for sorting.
What's the trick to this Bloomberg problem?+
Use a hash set to track what you've seen and append to the result only on the first sighting. Don't sort. Sorting destroys the original order, and the example [4,1,4,7,1,9] must return [4,1,7,9].
What time complexity should I aim for?+
O(n) time and O(n) extra space. With up to 2 * 10^5 elements, an O(n^2) approach that scans the result list for each value is risky. Set lookups are average O(1), so a single pass is the right target.
Is this hash-table dedupe pattern still asked?+
Order-preserving dedupe shows up regularly as a warm-up or as a building block inside bigger problems. Bloomberg reported this one in July 2020. Whether or not you see this exact title, set-based seen-tracking is worth having ready.
How do I prepare for this in 48 hours?+
Write the solution from scratch twice in your OA language. Test an empty array, all duplicates, and all unique values. Then say the complexity out loud. That's enough for a problem this size. Spend the rest of your time on harder patterns.