len(dishes) dishes. To cook dishes[i] you need every ingredient listed in needs[i]. An ingredient may itself be another dish from the book, which then has to be cooked first.
The pantry holds basic products, each in unlimited supply. A dish, once cooked, can also be used any number of times.
Return every dish that can be cooked, in any order. Note that dishes may depend on each other in a loop; such dishes cannot be made.dishes=['dough', 'pizza', 'soup'], needs=[['flour', 'water'], ['dough', 'cheese'], ['beet', 'water']], pantry=['water', 'flour', 'cheese'] → ['dough', 'pizza']
Dough needs flour and water, and dough plus cheese gives pizza. Soup is impossible without beets.
dishes=['jam', 'pie'], needs=[['pie'], ['jam', 'flour']], pantry=['flour', 'sugar'] → []
Jam needs pie and pie needs jam: a closed loop, so nothing can be made.
dishes=['tea'], needs=[['leaves', 'water']], pantry=['water', 'leaves', 'milk'] → ['tea']
Everything for tea is in the pantry.
len(dishes) = len(needs) ≤ 100len(needs[i]), len(pantry) ≤ 100_needs[i] contains duplicatesdishes=['dough', 'pizza', 'soup'], needs=[['flour', 'water'], ['dough', 'cheese'], ['beet', 'water']], pantry=['water', 'flour', 'cheese']
['dough', 'pizza']
Run checks the first 3 tests in your browser. Submit checks all 102 tests on the server, hidden ones included.