Dsa
Backtracking
Warm-up
Number Combinations
Given a list of unique integers and a target sum, find all unique combinations of numbers that add up to the target. Each number from the list may only be used once in the combination, and combinations should be sorted and printed in non-descending order.
Input Format:
- The first line contains a single integer n (1 ≤ n ≤ 10).
- The second line contains n space-separated integers representing the list of unique integers.
- The third line contains the target sum.
Output Format:
- Print each combination on a new line, with numbers separated by spaces, in sorted order.
Example:
Input:
5
1 2 3 4 5
5
Output:
1 4
2 3
5
Key concepts
backtrackingcombinationsrecursion
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