<p>Given two integers <code>n</code> and <code>k</code>, return <em>all possible combinations of</em> <code>k</code> <em>numbers chosen from the range</em> <code>[1, n]</code>.</p>

<p>You may return the answer in <strong>any order</strong>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> n = 4, k = 2
<strong>Output:</strong> [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
<strong>Explanation:</strong> There are 4 choose 2 = 6 total combinations.
Note that combinations are unordered, i.e., [1,2] and [2,1] are considered to be the same combination.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> n = 1, k = 1
<strong>Output:</strong> [[1]]
<strong>Explanation:</strong> There is 1 choose 1 = 1 total combination.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= n &lt;= 20</code></li>
	<li><code>1 &lt;= k &lt;= n</code></li>
</ul>

class Solution:
    def combine2(self, nums: List[int], l: int) -> List[List[int]]:
        """
        recursively *construct* a tree. See additional page.
        Time: O(C(n, l)), where n = len(nums)
        Space: O(C(n, l) * l)
        """
        n = len(nums)
        assert (n > 0) and (n >= l)

        if n == l:  # implying l > 0:
            return [nums]

        if l == 0:
            """
            Note: return [[]] not [] to enable the processing in for loop:

            lst1 = []
            for item in lst1:  # this for loop can not be executed
                print(f'item = {item}')

            lst2 = [[]]
            for item in lst2:
                print(f'item = {item}')  # output: []
            """
            return [[]]

        res = []
        for comb in self.combine2(nums[1: n], l - 1):  # comb is List[int]
            res.append([nums[0]] + comb)

        for comb in self.combine2(nums[1: n], l):
            res.append(comb)

        return res

    def combine(self, n: int, k: int) -> List[List[int]]:
        assert (n > 0) and (n >= k)
        nums = list(range(1, n + 1))
        return self.combine2(nums, k)
        
66450