77_ Combinations
[Medium][Backtracking]
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.
Example:
Solution:
Idea:
For integer 1, there are two possibilities: the subset does not contain 1, or it does contain 1.
In the first case: we return all subsets of size k from 2 ... n
In the second case: we return all subsets of size k-1 from 2 ... n and append 1 to each of them
Use the same idea for each integer.
Time Complexity: from EPI book, hard to compute because of the two parameters
Space Complexity:
Last updated