Medium · Backtracking

Combinations

Given integers n and k, return all combinations of k distinct numbers chosen from 1 to n, each combination once, in any order.

Examples

Example 1

n=4, k=2

Output: 6 combos

Example 2

n=5, k=3

Output: 10 combos

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Backtracking problems