
Combinations (medium)
Problem Statement
Given two integers n and k, return all possible combinations of k numbers chosen from the range [1, n].
Each combination must be a unique set of numbers, order of which does not matter.
Examples
-
Example 1:
- Input:
n = 3, k = 2 - Expected Output:
[[1, 2], [1, 3], [2, 3]] - Justification:
[[1, 2], [1, 3], [2, 3]]are all combinations of size 2, which we can create using[1, 2, 3].
- Input:
-
Example 2:
- Input:
n = 4, k = 1 - Expected Output:
[[1], [2], [3], [4]] - Justification:
[[1], [2], [3], [4]]are all combinations of size 1, which we can create using `[1, 2, 3, 4].
- Input:
-
Example 3:
- Input:
n = 5, k = 3 - Expected Output:
[[1, 2, 3], [1, 2, 4], [1, 2, 5], [1, 3, 4], [1, 3, 5], [1, 4, 5], [2, 3, 4], [2, 3, 5], [2, 4, 5], [3, 4, 5]] - Justification: We unique triplets using numbers 1 to 5, yielding ten different combinations.
- Input:
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory