Skip to the code
cf.
+10 XP

#302 Choose K Reviewers

easy

A code review tool picks k reviewers from a team of n people, numbered 1 to n. The order inside a team doesn't matter.

Write reviewerTeams(n, k) that returns every possible team. Write each team sorted ascending, and list the teams in sorted order: compare first members, then second members, and so on.

Example 1

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

There are C(4, 2) = 6 pairs, listed from smallest to largest.

Example 2

Input: n = 1, k = 1
Output: [[1]]

One person, one team.

Constraints

  • 1 <= n <= 10
  • 1 <= k <= n
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).