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.

&nbsp;
Example 1:

Input: n = 4, k = 2
Output: [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
Explanation: 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.


Example 2:

Input: n = 1, k = 1
Output: [[1]]
Explanation: There is 1 choose 1 = 1 total combination.


&nbsp;
Constraints:


	1 &lt;= n &lt;= 20
	1 &lt;= k &lt;= n


class Solution:
    def combine(self, n: int, k: int) -> List[List[int]]:
        return itertools.combinations(range(1, n+1), k)
class Solution {
    public List<List<Integer>> combine(int n, int k) {
        List<List<Integer>> subsets=new ArrayList<>();
        generatesubsets(1,n,new ArrayList(),subsets,k);
        return subsets;
    }
    void generatesubsets(int start,int n,List<Integer> current,List<List<Integer>> subsets,int k){
        if(current.size()==k){
            subsets.add(new ArrayList(current));
        }
        for(int i=start;i<=n;i++){
            current.add(i);
            generatesubsets(i+1,n,current,subsets,k);
            current.remove(current.size()-1);
        }
    }
}
class Solution {
public:
    void solve(vector<int> arr,vector<vector<int>> &ans,vector<int> &temp,int k,int x){
        if(temp.size()==k){
            ans.push_back(temp);
            return;
        }
        if(x>=arr.size()) return ;
        for(int i = x;i<arr.size();i++){
            temp.push_back(arr[i]);
            solve(arr,ans,temp,k,i+1);
            temp.pop_back();
        }
}
    vector<vector<int>> combine(int n, int k) {
        vector<vector<int>> ans;
        vector<int> temp;
        vector<int> arr;
        for(int i = 1;i<=n;i++) arr.push_back(i);
        solve(arr,ans,temp,k,0);
        return ans;
    }
};
var combine = function(n, k) {

    function helper (start, end, combo, subset, answer) {
        if (combo==0) {
            answer.push([...subset])
            return;
        }
        if (end - start + 1 < combo) {
            return;
        }
        if (start > end) {
            return;
        }
        subset.push(start)
        helper(start+1, end, combo - 1, subset, answer)

        subset.pop()
        helper(start+1, end, combo, subset, answer)
    }

    const answer = []
    helper(1, n, k, [], answer)
    return answer
};
Combinations