Ctrl K

Every Team of a Given Size

Medium
A club has players members, numbered from 1 to players. The coach needs a team of exactly size people. Return every possible team. A team is just a set of players: [1, 3] and [3, 1] are the same team and must appear once in the answer. The teams, and the numbers inside each team, may be listed in any order.
Example 1
players=4, size=3 → [[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]

There are 4 ways to pick three out of four players: each time one player sits on the bench.

Example 2
players=3, size=1 → [[1], [2], [3]]

A one-player team: one team per player.

Example 3
players=2, size=2 → [[1, 2]]
Constraints
  • 1 ≤ players ≤ 20
  • 1 ≤ size ≤ players
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsKeypad Words MediumAll Balanced Bracket Strings MediumWeight Sets for an Exact Load MediumCard Hands for an Exact Total MediumAll Orderings Medium
loading Python…
Input
players=4, size=3
Expected
[[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]

Run checks the first 3 tests in your browser. Submit checks all 39 tests on the server, hidden ones included.