FastPrepSubset Sum to Target
Problems/Subset Sum to Target

Subset Sum to Target

Dream11 logoDream11● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report describes a subset-sum-to-k question in a Dream11 DSA round, and does not limit the signs of the integers. We chose the limit of at most 30 elements, how the empty subset is treated, and an integer result. Our version is about 97% the same as the reported question.

You are given an array nums of signed integers and a signed integer target. Determine whether some subset of array indices has values summing exactly to target. Each index may be selected at most once, and the empty subset is allowed.

Return 1 if such a subset exists; otherwise return 0.

Function

hasSubsetSum(nums: int[], target: int) → int

Examples

Example 1

nums = [3,34,4,12,5,2]target = 9return = 1

Selecting 4 and 5 reaches the target 9.

Example 2

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

The possible non-empty sums are 2, -4, 7, -2, 9, 3, and 5, so no subset reaches 1.

Constraints

  • 0 <= nums.length <= 30.
  • -10^9 <= nums[i], target <= 10^9.
  • Use 64-bit arithmetic for intermediate subset sums.

More Dream11 Onsite Interview questions

  • Minimum Index Distance Between Two ValuesONSITE INTERVIEW · Seen Feb 2026
  • Partition Into K-Size Consecutive GroupsONSITE INTERVIEW · Seen Feb 2026

Similar questions at other companies

  • Assign Escalations to TeamsAmazon · ONSITE INTERVIEW
  • Distinct Subset SumsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Count Subsets With a Target SumSafe Security · ONSITE INTERVIEW
  • Maximum Subarray Sum with One DeletionOracle · ONSITE INTERVIEWOracle interview questions
  • Best Time to Buy and Sell Stock IIKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Coin ChangeMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Maximum SubarrayUpstart · ONSITE INTERVIEWUpstart interview questions
  • Smallest Sufficient TeamExpedia · ONSITE INTERVIEWExpedia interview questions
  • Maximum Product SubarrayHartford Financial Services · ONSITE INTERVIEWHartford Financial Services interview questions
  • Word BreakMoveworks · ONSITE INTERVIEWMoveworks interview questions
All Dream11 interview questionsSee Dream11 hiring insights
Saved
class Solution {
    public int hasSubsetSum(int[] nums, int target) {
        // Return 1 when a subset reaches target, otherwise 0.
    }
}
Checking account…