Combinations Problem
Combinations Problem — ExecCode Medium DSA Practice
Solve the Combinations problem on ExecCode. Free online medium DSA practice in Backtracking. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given two integers n and k, return all possible combinations of k numbers chosen from the range [1, n]. You may return the answer in any order. Combinations are unordered — [1,2] is the same as [2,1]. Example: n = 4, k = 2 → [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
Examples
Input n = 3, k = 2; Output [[1, 2], [1, 3], [2, 3]]. Input n = 4, k = 2; Output [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]
Constraints
1 <= n <= 20 1 <= k <= n
Practice Combinations free on ExecCode. Browse DSA problems, topic map, and placement guides.