Combinations
Real-world version: Tasting Flight Line-upsThe statement here is our own: the same inputs, outputs and technique.
A cellar stores casks barrels, numbered 1 through casks. A tasting flight is a selection of exactly pour different barrels; two flights are the same flight when they draw from the same set of barrels, no matter which barrel was poured first.
Return every flight the cellar can serve. Each flight must list its barrel numbers in increasing order, and the flights themselves may be returned in any order.
Examples
Example 1
- Input
- casks = 5, pour = 3
- Output
- [[1,2,3],[1,2,4],[1,2,5],[1,3,4],[1,3,5],[1,4,5],[2,3,4],[2,3,5],[3,4,5],[2,4,5]]
Ten different sets of three barrels can be drawn from five, and each one is listed with its barrel numbers increasing.
Example 2
- Input
- casks = 3, pour = 3
- Output
- [[1,2,3]]
A flight of three from three barrels can only draw all of them, so there is a single flight.
Example 3
- Input
- casks = 2, pour = 1
- Output
- [[2],[1]]
Each barrel on its own is a flight of one, so both single-barrel flights are returned; the order of the flights does not matter.
Constraints
- 1 <= casks <= 20
- 1 <= pour <= casks
The values you return may be in any order.
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def list_flights(casks: int, pour: int) -> list[list[int]]:public List<List<Integer>> listFlights(int casks, int pour)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 8 test cases: 8 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's