Combination Sum III
Problem Statement
You need a set of k different numbers, chosen from 1 to 9, whose sum is exactly n. Each number can be used at most once.
Return every set that works. Each set is a list of k numbers. Sets can come back in any order, but no set may appear twice.
Two integers, k and n.
A list of all valid sets. Each set has k numbers, and they add up to n.
1 + 2 + 4 = 7. No other set of three different numbers adds up to 7.
Each of these three sets has three different numbers that add up to 9.
The smallest four different numbers are 1 + 2 + 3 + 4 = 10, which is already more than 1. So there are no answers.
- • 2 ≤ k ≤ 9
- • 1 ≤ n ≤ 60
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
Check every subset of 1…9; keep the ones with k numbers and sum n
Pick numbers in increasing order; stop at k numbers, and stop when the sum would pass n
Each number from 1 to 9 is in the set or out of it. That gives 2⁹ = 512 subsets. Keep a subset only if it has exactly k numbers and its numbers add up to n.
Recognition rule for this sub-pattern:
Unlock Complete Visual Walkthrough & Optimal C++
The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.
First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.
How this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like Backtracking translate into production architectures and low-level memory mechanics.
Foundations: Object-Oriented Principles in C++23
Class invariants, pure virtual interfaces, and RAII smart pointers.
Food Delivery System (Zomato Architecture)
Real-world machine coding application of algorithms and design patterns.
Pointers vs References Deep Dive
Pointer arithmetic and memory layout under the hood.
Virtual Method Table (vtable) & Memory Layout
Polymorphism, vptr overhead, and multiple inheritance in memory.