Find Cookable Recipes
Updated
Problem statement
You are given a list of recipes. Each recipe is a list of ingredient names. Return the zero-based indices of the recipes that can be made from available, in increasing index order.
For this exercise, assume a recipe is possible when every ingredient name it lists is available. Names are case-sensitive. Quantities are not modeled, so repeated names do not increase a requirement. Check each recipe independently: ingredients are not used up, and making a recipe does not add a new ingredient.
Return an empty list when no recipe is possible.
Function
possibleRecipes(recipes: String[][], available: String[]) → int[]Examples
Example 1
recipes = [["flour","egg"],["rice","water"],["egg"]]available = ["egg","flour"]return = [0,2]Recipe 0 needs flour and egg, which are both available. Recipe 1 is missing rice and water. Recipe 2 only needs egg.
Example 2
recipes = [["Salt"],["salt"]]available = ["salt"]return = [1]Names are case-sensitive. The available name salt satisfies recipe 1 but does not satisfy Salt in recipe 0.
Example 3
recipes = []available = ["egg"]return = []There are no recipes to select.
Constraints
0 <= recipes.length <= 200.- Each recipe contains
1to50ingredient names. 0 <= available.length <= 1000.- The total number of ingredient-name occurrences across all recipes and
availableis at most2000. - Every ingredient name has
1to20characters. - Ingredient names contain only English letters, uppercase or lowercase.
More Palantir interview questions
- Map and Accumulate Learning QueriesONSITE INTERVIEW · Seen Oct 2026
- Relational Learning QueriesONSITE INTERVIEW · Seen Apr 2025
- Find Unmet Users With Shared InterestsONSITE INTERVIEW · Seen Mar 2025
- Maximum Profit with Repeated Stock TradesONSITE INTERVIEW · Seen Sep 2024
- Minimum Calls for Repeated API LookupsONSITE INTERVIEW · Seen Oct 2022
- Simulate Multiplayer WarONSITE INTERVIEW · Seen Nov 2019
- Trace Terminal Company OwnershipONSITE INTERVIEW · Seen Nov 2019
- Query Words Within K PositionsPHONE SCREEN · Seen Nov 2026
- Basic Item DiscountsOA · Seen Nov 2026
- Optimize Discount Selection Under a Point BudgetOA · Seen Nov 2026
Similar questions at other companies
- Filter Pins by Excluded IDsPinterest · ONSITE INTERVIEWPinterest interview questions
- Longest Dictionary Word from Nine LettersGoogle · ONSITE INTERVIEWGoogle interview questions
- K-Second Message SuppressionMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Logger Rate LimiterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
- Loyal Customers by Two-Day Product VarietyAmazon · ONSITE INTERVIEW
- Find Nodes with Invalid Parent LevelsZip · ONSITE INTERVIEWZip interview questions
- Count Word FrequenciesBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Most Voted CandidateExpedia · ONSITE INTERVIEWExpedia interview questions
- List Each Name Once, AlphabeticallyDocuSign · ONSITE INTERVIEWDocuSign interview questions
- Process Shopping Records, Promotions, and Display OrderInstacart · PHONE SCREEN · ONSITE INTERVIEWInstacart interview questions