Fill the blank
Fill the blank to stop when too few players remain.
n, k = 5, 3
out: list[list[int]] = []
calls = 0
def grow(start: int, team: list[int]) -> None:
global calls
calls += 1
if len(team) == k:
out.append(team[:])
return
need = k - len(team)
for p in range(start, ____):
team.append(p)
grow(p + 1, team)
team.pop()
grow(1, [])
print(len(out), out[-1], calls)Choose an answer, then open Show answer below to check it.
Show answer
Answer: A n - need + 2
Right: the last useful start leaves exactly need - 1 players after it.
With 3 still needed out of players 1 to 5, the first pick can be at most 3; the bound encodes that.
Why not the others?
- B n + 1. The same 10 teams, but 26 calls instead of 20: the extra calls start teams that cannot be filled.
- C n - need. That cuts off valid teams: only [1, 2, 3] is found, in 4 calls.