Trains the technique from
LeetCode 2115Find All Possible Recipes from Given SuppliesThis 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 model workshop owns a drawer of components and a book of fabrication cards.
Card i makes the part named builds[i], and running it consumes one of every component named in needs[i]. A name on a card may refer to something already in the drawer, to a part that another card makes, or to something the workshop has no way of getting at all.
The drawer starts out holding the components named in stock. A card may be run whenever every name on its list is available, and the part it makes becomes available from then on. Availability is not used up: once a name is available, any number of cards may draw on it, in any order, as often as they like.
Return the names of all the parts the workshop can end up making. The names may be returned in any order.
Every name in builds and stock taken together is distinct, and no card lists the same name twice.
Example 1
The drawer holds ply and glue, so the second and third cards can be run at once, and the two parts they make are exactly what the first card lists.
Example 2
The drawer holds only copper, and neither card lists copper, so neither card's list is met while the drawer stands as it is.
Example 3
The second card needs only steel, which is in the drawer. The first card also lists a rivet, a name that is neither in the drawer nor made by any card.
Example 4
The lens card lists only glass, which is in the drawer, so it runs and the lens joins the available names. No other card's list is covered by glass, filament and the lens.
The values you return may be in any order.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def find_all_recipes(builds: list[str], needs: list[list[str]], stock: list[str]) -> list[str]:public List<String> findAllRecipes(String[] builds, List<List<String>> needs, String[] stock)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.