Anthropic's "Recipe Manager" interview question focuses on designing an OOP-based system for managing recipes, emphasizing data structures, search, and sorting capabilities. It typically involves implementing a class hierarchy and methods for efficient querying.
Design a RecipeManager class to store and manage recipes, each with attributes like ID, name, ingredients (list of strings), cuisine type, prep time (minutes), and rating (float 0-5). Support adding recipes, deleting by ID, and advanced search/sorting operations. Use appropriate data structures (e.g., lists, maps, or trees) for efficiency, and demonstrate OOP principles like encapsulation and polymorphism. Constraints prioritize O(log n) or better for search/sort where possible on up to 10^5 recipes.[1][9]
Example 1: Adding and Basic Search
Input: add(1, "Pasta", ["pasta", "tomato"], "Italian", 20, 4.5) add(2, "Sushi", ["rice", "fish"], "Japanese", 45, 4.8) search_ingredient("pasta") → [1] search_cuisine("Italian") → [1]
Example 2: Top Rated with Filter
top_rated(1, "Japanese") → [2] top_rated(2) → [2, 1]
Example 3: Sorted by Prep Time
sort_prep_time(0, 30) → [1]
These examples illustrate substring matching for ingredients, exact cuisine match, and stable sorting.[3][5]