Check if each recipe is a contiguous subsequence
Company: Snowflake
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Quick Answer: This question evaluates proficiency in algorithmic sequence matching and contiguous subarray detection, encompassing array/string pattern matching and time/space complexity reasoning.
Part 1: Efficient Contiguous Recipe Lookup
Constraints
- 0 <= len(ingredients) <= 200000
- 0 <= len(recipes) <= 200000
- 0 <= sum(len(recipe) for recipe in recipes) <= 200000
- Items are hashable values such as integers or strings
- An empty recipe should be treated as present
Examples
Input: ([1, 2, 3, 4, 5], [[2, 3], [4, 5], [3, 5], [1], []])
Expected Output: [True, True, False, True, True]
Explanation: [2, 3], [4, 5], [1], and [] appear contiguously; [3, 5] does not.
Input: (['egg', 'milk', 'flour', 'sugar'], [['milk', 'flour'], ['flour', 'milk'], ['sugar'], ['egg', 'milk', 'flour', 'sugar', 'vanilla']])
Expected Output: [True, False, True, False]
Explanation: Only exact contiguous matches count.