# Combinations

Given two integers _n_ and _k_, return all possible combinations of _k_ numbers out of 1 ... _n_.

**Example:**

```
Input: n = 4, k = 2
Output:
[
  [2,4],
  [3,4],
  [2,3],
  [1,2],
  [1,3],
  [1,4],
]
```

```java
class Solution {
    public static List<List<Integer>> combine(int n, int k) {
        List<List<Integer>> ans = new ArrayList<List<Integer>>();
        backTrack(ans, new ArrayList<Integer>(), 1, n, k);
        return ans;
    }

    public static void backTrack(List<List<Integer>> ans, List<Integer> temp, int start, int n, int k) {
        if (k == 0) {
            ans.add(new ArrayList<Integer>(temp));
            return;
        }
        for (int i = start; i <= n; i++) {
            temp.add(i);
            backTrack(ans, temp, i + 1, n, k - 1);
            temp.remove(temp.size() - 1);
        }
    }
}
```
