Subsets
Updated
Problem statement
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[]) → List<List<Integer>>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
numsare unique.
More Bloomberg LP Onsite Interview questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Decode StringPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Minimum Replacements to Make Two Strings AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Currency Conversion RatePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- SubsetsTemu · PHONE SCREENTemu interview questions
- Maximum Unique-Character Word SubsetMeta · ONSITE INTERVIEWMeta interview questions
- SubsetsGoogle · ONSITE INTERVIEWGoogle interview questions
- Optimal Account BalancingAmazon · ONSITE INTERVIEW
- Count Legal Outfit CombinationsDuolingo · OADuolingo interview questions
- Largest Number Below N from Reusable DigitsByteDance · PHONE SCREENByteDance interview questions
- Find the Two Unique NumbersZomato / Eternal · ONSITE INTERVIEWZomato / Eternal interview questions
- Unique Single-Use Sum CombinationsLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Minimum Cost for a Target WeightPace Stock Broking Services · PHONE SCREEN
- Bounded Combination Sum with Signed CandidatesConfluent · ONSITE INTERVIEWConfluent interview questions