Positive Subset Sum
Updated
Problem statement
You are given an array nums of positive integers and a positive integer target. Return true when some subset of array positions sums exactly to target; otherwise return false.
Each array position may be selected at most once. Equal values at different positions are separate choices.
As an interview follow-up, explain how to reconstruct and return one concrete subset after determining that the target is reachable.
Function
canReachTarget(nums: int[], target: int) → booleanExamples
Example 1
nums = [12,1,61,5,9,2]target = 24return = trueThe positions containing 12, 9, 2, and 1 sum to 24.
Example 2
nums = [2,4,6]target = 5return = falseNo subset of the three positive values sums to 5.
Example 3
nums = [5,5,11]target = 10return = trueThe two occurrences of 5 occupy different positions and may both be selected.
Constraints
1 <= nums.length <= 200.1 <= nums[i] <= 10000.1 <= target <= 20000.
More Confluent Onsite Interview questions
- Implement tail -nPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Sudoku Board ValidationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Sudoku Puzzle SolverPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Sequential Phrase Search Across DocumentsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Bounded Combination Sum with Signed CandidatesONSITE INTERVIEW · Seen Oct 2026
- Detect a Silent SensorONSITE INTERVIEW · Seen Sep 2026
- Build an Inverted Document IndexONSITE INTERVIEW · Seen Sep 2026
- Combination Sum with Unlimited ReuseONSITE INTERVIEW · Seen Sep 2026
- Word Search Across DocumentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Windowed Key-Value MapPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
Similar questions at other companies
- Count Subsets With a Target SumSafe Security · ONSITE INTERVIEW
- 0/1 Knapsack with Weight and Volume LimitsGoogle · ONSITE INTERVIEWGoogle interview questions
- 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
- Word BreakAmazon · PHONE SCREEN · ONSITE INTERVIEW
- 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