Instacart software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
pattern and a log string, both consisting of uppercase letters and the wildcard character *. The * wildcard matches...Input: String['apple', 'banana', 'apple', 'orange', 'banana', 'banana']), write a function most_frequent_item(cart: List[str]) -> Tuple[str, int] that returns the item that appears most frequently in the cart and its count. If multiple items have the same count, return any one of them.most_frequent_item(cart: List[str]) -> Tuple[str, int]['apple', 'banana', 'apple', 'orange', 'banana', 'banana'] ('banana', 3) ['grape', 'apple', 'grape', 'orange', 'apple'] ('grape', 2) n deliveries and a total available time T, return the maximum number of deliveries that can be completed.def max_deliveries(delivery_times: List[int], total_time: int) -> int:, total_time = 7, total_time = 5weights, where each value represents the weight of a grocery item. The total weight of any batch cannot exceed a limit maxWeight. Write a function that finds the maximum number of items you can include in a single batch while respecting the maxWeight. Key constraints are that the items must be taken in order from the weights array.def max_items_in_batch(weights: List[int], maxWeight: int) -> int:weights = [2, 3, 5, 2, 8], maxWeight = 10 4 [2, 3, 5], and one additional item with weight 2 which totals 10 (i.e., 2 + 3 + 5 = 10).weights = [1, 1, 1, 1, 1], maxWeight = 3 3 1 each totaling 3.1 <= len(weights) <= 10001 <= weights[i] <= 1001 <= maxWeight <= 10001 and open paths by 0, write a function to find the shortest path from the starting point to the destination. The function should return the minimum number of steps needed to reach the destination, or -1 if the destination cannot be reached.def shortest_delivery_path(store: List[List[int]], start: Tuple[int, int], destination: Tuple[int, int]) -> int: store = [[0,0,0],[0,1,0],[0,0,0]], start = (0, 0), destination = (2, 2) 4 [(0,0) -> (0,1) -> (0,2) -> (1,2) -> (2,2)], with 4 steps.store = [[0,1],[0,0]], start = (0, 0), destination = (1, 1) 2 [(0,0) -> (1,0) -> (1,1)], with 2 steps.1 <= len(store) <= 100 1 <= len(store[i]) <= 100 deliveryPoints representing the sequence of delivery locations and an integer maxStops which represents the maximum number of stops a shopper can make, write a function that returns the shortest route for the shopper that includes all the delivery points up to maxStops. Each delivery point has a distance associated with it. You can assume that the list is already sorted by the distance from the store. def shortest_delivery_route(deliveryPoints: List[int], maxStops: int) -> List[int]:deliveryPoints = [2, 3, 5, 8, 10], maxStops = 3[2, 3, 5] deliveryPoints = [1, 4, 6, 7], maxStops = 2[1, 4] 1 <= len(deliveryPoints) <= 1001 <= deliveryPoints[i] <= 10^61 <= maxStops <= len(deliveryPoints)items that represent customer orders, each an item in a string format, and an integer k, write a function to return the k most frequently purchased items in order of their frequency. If two items have the same frequency, return them in the order they first appeared in the list.def top_k_frequent(items: List[str], k: int) -> List[str]:items = ['apple', 'banana', 'apple', 'orange', 'banana', 'banana'], k = 2['banana', 'apple']items = ['carrot', 'carrot', 'potato', 'onion', 'carrot', 'potato'], k = 1['carrot']1 <= len(items) <= 10^41 <= k <= len(items)def longest_consecutive_items(items: List[int]) -> int:[1, 3, 2, 4, 5] 5 1, 2, 3, 4, 5 form a consecutive subarray.[10, 2, 3, 11, 4, 5, 1] 5 1, 2, 3, 4, 5 form a consecutive subarray. 1 <= len(items) <= 1000 10^6.as_of selects the mutation with the greatest timestamp less than or equal to as_of. Return None if no such mutation exists or if the selected mutation is a deletion.timestamp with ttl_seconds = t is visible only while as_of < timestamp + t. An expired selected version returns None; never fall back to an older version. A missing TTL means no expiration. A quantity of zero is still a valid, retrievable product version.RetailerCatalogHistory() — construct an empty store.set_product(retailer_id: str, sku: str, timestamp: int, price_cents: int, quantity: int, ttl_seconds: Optional[int] = None) -> None — insert or replace a timestamped product version.delete_product(retailer_id: str, sku: str, timestamp: int) -> None — insert or replace a timestamped deletion, including for a previously unknown product.get_product(retailer_id: str, sku: str, as_of: int) -> Optional[ProductSnapshot] — retrieve the visible version at the requested time.list_available(retailer_id: str, as_of: int) -> List[ProductSnapshot] — retrieve visible, positive-quantity products in SKU order.ProductSnapshot has typed fields sku: str, price_cents: int, and quantity: int.catalog = RetailerCatalogHistory()
catalog.set_product("r1", "milk", 10, 499, 6)
catalog.set_product("r1", "milk", 20, 549, 2, 5)
catalog.get_product("r1", "milk", 19)
catalog.get_product("r1", "milk", 24)
catalog.get_product("r1", "milk", 25)
catalog.get_product("r1", "milk", 9)[
{"sku": "milk", "price_cents": 499, "quantity": 6},
{"sku": "milk", "price_cents": 549, "quantity": 2},
null,
null
]20 + 5 = 25, so the lookup at 25 returns null without reviving the version at 10. No version exists at time 9.Example 2:catalog = RetailerCatalogHistory()
catalog.set_product("r1", "milk", 10, 499, 6)
catalog.delete_product("r1", "milk", 30)
catalog.set_product("r1", "milk", 20, 529, 3)
catalog.set_product("r1", "apples", 15, 199, 4)
catalog.set_product("r1", "bread", 15, 399, 0)
catalog.set_product("r2", "milk", 10, 459, 8)
catalog.list_available("r1", 25)
catalog.get_product("r1", "milk", 35)
catalog.set_product("r1", "milk", 30, 559, 1)
catalog.list_available("r1", 35)
catalog.get_product("r2", "milk", 35)[
[
{"sku": "apples", "price_cents": 199, "quantity": 4},
{"sku": "milk", "price_cents": 529, "quantity": 3}
],
null,
[
{"sku": "apples", "price_cents": 199, "quantity": 4},
{"sku": "milk", "price_cents": 559, "quantity": 1}
],
{"sku": "milk", "price_cents": 459, "quantity": 8}
]r2 is independent.Constraints[0, 10^12]; prices and quantities are integers in [0, 10^9]; TTL is either absent or an integer in [1, 10^9].Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free