FastPrepGeneralized N-Sum
Problems/Generalized N-Sum

Generalized N-Sum

Bloomberg LP logoBloomberg LP● HardNEW GRADONSITE INTERVIEW

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for an array, n, and target and confirms in a reply that every length-n selection summing to target must be returned. It compares the task with 4Sum and asks for a more optimal approach than plain backtracking. This practice version uses sorting, duplicate elimination, and a two-pointer base case.

Given an integer array nums, an integer n, and an integer target, return every unique combination of exactly n values whose sum is target.

  • Each array index may be selected at most once.
  • Values within each combination must be in nondecreasing order.
  • Return unique combinations in lexicographic order.

Function

nSum(nums: int[], n: int, target: int) → int[][]

Examples

Example 1

nums = [1,0,-1,0,-2,2]n = 4target = 0return = [[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]

These are the three unique four-value combinations summing to zero.

Example 2

nums = [2,2,2,2,2]n = 4target = 8return = [[2,2,2,2]]

Many index choices yield the same value combination, which appears only once.

Example 3

nums = [1,2,3]n = 2target = 10return = []

No pair reaches the target.

Constraints

  • 2 <= nums.length <= 50.
  • 2 <= n <= min(5, nums.length).
  • -10^6 <= nums[i], target <= 10^6.
  • Intermediate sums fit in signed 64-bit integers.

More Bloomberg LP Onsite Interview questions

  • Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 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
  • 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

Similar questions at other companies

  • Intersect Multiple Interval ListsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Merge Sorted Squares of Two ArraysWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • 3Sum SmallerSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Sort Ones, Twos, and Threes In PlaceAgoda · PHONE SCREEN · ONSITE INTERVIEWAgoda interview questions
  • Minimum Station Tracks for a Train ScheduleBNSF Railway · ONSITE INTERVIEWBNSF Railway interview questions
  • Merge Sorted ArrayDP World · ONSITE INTERVIEW
  • 4SumAmazon · ONSITE INTERVIEW
  • Sort ColorsCapital One · ONSITE INTERVIEWCapital One interview questions
  • 3SumOptimus Information · ONSITE INTERVIEWOptimus Information interview questions
  • Merge Sort Report with a Noisy ComparatorMercor · ONSITE INTERVIEWMercor interview questions

Bloomberg LP interview experiences

  • Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
  • Bloomberg SWE Intern Interview Questions: 68 Questions
  • Bloomberg Interview Questions, Level Not Reported: 65 Questions
  • Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
  • Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
  • Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public int[][] nSum(int[] nums, int n, int target) {
        // Write your code here.
    }

}
Checking account…