Teams of a Given Size
names is a list of different strings. Return every possible team of exactly k of them. Each team is a list that keeps its members in the order they have in names, and the teams themselves may be returned in any order. When k is 0 the only team is the empty list, so return [[]]; when k is larger than the number of names there are no teams, so return [].
For example, names = ["ann", "bob", "cy"] and k = 2 give [["ann", "bob"], ["ann", "cy"], ["bob", "cy"]].
Example 1
names ["ann","bob","cy"]
k 2
returns [["ann","bob"],["ann","cy"],["bob","cy"]]
Three names give three ways to pick two of them, each kept in the original order.
Example 2
names ["ann","bob"]
k 0
returns [[]]
Picking nobody is the one and only team of size 0.
Constraints
0 <= len(names) <= 80 <= k <= 9- Each name has 1 to 6 lowercase letters and no two names are equal
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Recursion problems
- The Climb FunctionEasy
- Count the BlobsMedium
- Discs After k MovesMedium
- Distinct Arrangements in OrderMedium
- Every Route Through the GardenMedium
- Fair SplitMedium
- Fill In the BracketsMedium
- Hidden Word CountMedium