Question bank › Dynamic Programming
Dsa Dynamic Programming Easy

Count Distinct Subsets Sum

You are given an array of non-negative integers. Your task is to count the number of distinct sums that can be formed by subsets of this array. Two subsets that create the same sum count as one, and the empty subset (sum 0) is also counted. For example, given the array [1, 2, 2], the distinct sums are {0, 1, 2, 3, 4}. Input Format: - The first line contains an integer n (1 ≤ n ≤ 100), the number of elements in the array. - The second line contains n space-separated integers, the elements of the array. Output Format: - Output a single integer, the count of distinct subsets sums. Example: Input: 3 1 2 2 Output: 5

Key concepts

dynamic_programmingsubset_sumcombinatorics

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.