Subsets
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Bloomberg reported this one in November 2025, and the catch is hiding in one sentence: the output has to come back in increasing binary-mask order, where bit i means nums[i] is in the subset. That's Subsets, but with a fixed ordering rule that a standard backtracking answer won't match. With nums.length capped at 10, there are at most 1024 subsets, so brute force is fine. If you blank on the ordering mid-assessment, StealthCoder runs invisibly on your desktop and gives you the solution in real time as a safety net.
The problem
Given an integer array nums whose elements are unique, return all of its subsets, including the empty subset. Within each subset, preserve the elements' original input order. Return the subsets in increasing binary-mask order: bit i indicates whether nums[i] belongs to that subset. Function subsets(nums: int[]) → int[][] Examples Example 1 nums = [1,2,3] return = [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]] The eight outputs correspond to masks 000 through 111. Example 2 nums = [0] return = [[],[0]] A one-element array has the empty subset and the subset containing that element. Constraints 1 <= nums.length <= 10. -10 <= nums[i] <= 10. All values in nums are unique.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is to skip recursion and loop mask from 0 to (1 << n) - 1. For each mask, walk i from 0 to n-1 and push nums[i] when bit i is set. That gives the original element order inside each subset and the exact mask ordering the examples show, so [1] comes before [2] and [1,2] comes before [3]. The common pitfall is classic DFS backtracking. It returns the right subsets in the wrong order: [],[1],[1,2],[1,2,3],[1,3],[2]... and fails the comparison. Another trap is treating bit 0 as the leftmost element in a printed mask. Here bit 0 is nums[0]. Complexity is O(n * 2^n) time and the same for output space. Constraints are tiny, so don't optimize. If the ordering logic slips under pressure, StealthCoder is the hedge during the live OA. It reads the statement and hands you the mask loop.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Subsets 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. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as subsets. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Bloomberg's OA.
Bloomberg reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Subsets FAQ
How hard is Subsets really in this Bloomberg OA?+
Easy to medium. The algorithm is simple and n is at most 10. The difficulty is the required output order. If you know the bitmask loop, it's about ten lines. If you only know backtracking, you'll likely get the order wrong.
What's the trick to getting the right output order?+
Iterate mask from 0 up to 2^n - 1. For each mask, check bits 0 through n-1 in order and append nums[i] when bit i is set. That produces both the mask ordering and the within-subset order the problem demands.
Can I use backtracking instead?+
You can, but plain include/exclude recursion won't emit masks in increasing order. You'd need to sort results or restructure the recursion to match. The bitmask loop is shorter and matches the spec directly, so use it.
What are the edge cases to test?+
Test a single-element array like [0], which should return [[],[0]]. Also test negative values and a full length-10 input. Make sure the empty subset comes first and that your output has exactly 2^n subsets, with none duplicated.
How should I prepare for this in 48 hours?+
Write the bitmask subset loop from memory twice. Trace nums = [1,2,3] by hand through masks 000 to 111 and confirm it matches Example 1. Then glance at the time and space cost, O(n * 2^n), so you can explain it if asked.