All problems
0223MediumBacktracking

Tasting Flight Line-ups

Tracked in this browser only
Write code

Trains the technique from

LeetCode 77Combinations

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def list_flights(casks: int, pour: int) -> list[list[int]]:
Java
public List<List<Integer>> listFlights(int casks, int pour)
September 7
Apply