Instacart logo

Instacart Medium Interview Questions

11 medium-level practice questions for Instacart technical interviews

Instacart software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.

Software Engineer Backend Engineer Frontend Engineer Full Stack Engineer Mobile Engineer Data Engineer Data Scientist ML Engineer DevOps Engineer DevOps Engineer Product Manager SRE Security Engineer Engineering Manager Data Analyst UX/UI Designer QA Engineer
coding Medium Verified Question #1

1. Pattern First Occurrence


Category: String coding problem
You are given a search pattern and a log string, both consisting of uppercase letters and the wildcard character *. The * wildcard matches...
Input: String
Output: Computed result
Want to practise this one?
Create a free account to open the full question and practise Instacart questions with AI.
Sign up free
coding Medium Verified Question #2

2. Cipher Grid Decoder


Category: Grid/matrix coding problem
A cipher system encodes characters inside a grid. The grid rows contain uppercase letters. The coordinate system places the origin at the bottom-left...
Input: 2D grid
Output: Computed result
coding Medium Verified Question #3

3. Config Chain Resolver


Category: Array coding problem
A configuration management system resolves config values through chains of references.
Input: Array
Output: Computed result
coding Medium hash map #1

1. Hash Map — Find the Most Frequent Item in a Shopping Cart

Background: At Instacart, understanding customer preferences is crucial for enhancing user experience. Analyzing the most frequently purchased items helps optimize inventory and offers.
Problem statement: Given a list of strings representing item names in a shopping cart (e.g., ['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.
Function/class signature:
  • most_frequent_item(cart: List[str]) -> Tuple[str, int]


Example 1:
Input: ['apple', 'banana', 'apple', 'orange', 'banana', 'banana']
Output: ('banana', 3)
Explanation: 'banana' appears 3 times, more than any other item.
Example 2:
Input: ['grape', 'apple', 'grape', 'orange', 'apple']
Output: ('grape', 2)
Explanation: Both 'grape' and 'apple' appear 2 times, but 'grape' can be returned.
Constraints:
  • 1 ≤ |cart| ≤ 10^6

  • Each item name is a non-empty string of length at most 100.
Want to practise this one?
Create a free account to open the full question and practise Instacart questions with AI.
Sign up free
coding Medium dynamic programming #2

2. Dynamic Programming — Maximize Delivery Count

Background: Instacart needs efficient algorithms to optimize delivery logistics and maximize the number of deliveries handled within a specific timeframe. This impacts customer satisfaction and operational costs.
Problem statement: You are tasked with implementing a function that determines the maximum number of deliveries a delivery person can make within a time window. Each delivery requires a certain amount of time, and the delivery person cannot exceed their total available time. Given a list of delivery times for n deliveries and a total available time T, return the maximum number of deliveries that can be completed.
Function/class signature:
  • def max_deliveries(delivery_times: List[int], total_time: int) -> int:


Example 1:
  • Input: delivery_times = [2, 3, 4, 5], total_time = 7

  • Output: 2

  • Explanation: The delivery person can complete two deliveries taking 2 and 3 units of time, summing up to 5, which is less than 7.


Example 2:
  • Input: delivery_times = [1, 2, 3, 4], total_time = 5

  • Output: 2

  • Explanation: The delivery person can complete two deliveries taking 1 and 2 units, summing to 3, which is less than 5.


Constraints:
  • 1 <= len(delivery_times) <= 100

  • 1 <= delivery_times[i] <= 100

  • 1 <= total_time <= 1000`
coding Medium two pointers #3

3. Two Pointers — Find Optimal Grocery Batch Size

1. Background: Instacart is focused on efficient grocery delivery, and determining which items can be combined into a single batch can optimize delivery operations. This problem relates to managing the batch size to minimize delivery costs while maximizing efficiency.
2. Problem statement: You are given an array of integers weights, 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.
3. Function/class signature:
- def max_items_in_batch(weights: List[int], maxWeight: int) -> int:
4. Example 1:
- Input: weights = [2, 3, 5, 2, 8], maxWeight = 10
- Output: 4
- Explanation: You can combine items with weights [2, 3, 5], and one additional item with weight 2 which totals 10 (i.e., 2 + 3 + 5 = 10).
5. Example 2:
- Input: weights = [1, 1, 1, 1, 1], maxWeight = 3
- Output: 3
- Explanation: The best option is to take 3 items with weight 1 each totaling 3.
6. Constraints:
- 1 <= len(weights) <= 1000
- 1 <= weights[i] <= 100
- 1 <= maxWeight <= 1000
coding Medium graph #4

4. [Graph] — Shortest Path for Deliveries

Background: Instacart needs an efficient method to calculate the shortest delivery path for its shoppers navigating through grocery stores. This problem is crucial for optimizing delivery times, improving customer satisfaction, and enhancing operational efficiency.
Problem statement: Given a grid representing a grocery store layout where obstacles (shelves or areas that cannot be traversed) are denoted by 1 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.
Function/class signature:
  • def shortest_delivery_path(store: List[List[int]], start: Tuple[int, int], destination: Tuple[int, int]) -> int:

Example 1:
  • Input: store = [[0,0,0],[0,1,0],[0,0,0]], start = (0, 0), destination = (2, 2)

  • Output: 4

  • Explanation: The path is [(0,0) -> (0,1) -> (0,2) -> (1,2) -> (2,2)], with 4 steps.

Example 2:
  • Input: store = [[0,1],[0,0]], start = (0, 0), destination = (1, 1)

  • Output: 2

  • Explanation: The path is [(0,0) -> (1,0) -> (1,1)], with 2 steps.

Constraints:
  • 1 <= len(store) <= 100

  • 1 <= len(store[i]) <= 100

  • Start and destination coordinates are within bounds and valid (0, 0) to (len(store) - 1, len(store[0]) - 1).
coding Medium two pointers #5

5. Two Pointers — Finding the shortest path for shopping delivery

Background: In a complex shopping delivery network, Instacart aims to optimize the paths of shoppers to minimize delivery times. Using efficient algorithms helps in dynamically calculating the best delivery routes based on various factors.
Problem statement: Given a list of 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.
Function/class signature:
  • def shortest_delivery_route(deliveryPoints: List[int], maxStops: int) -> List[int]:


Example 1:
Input: deliveryPoints = [2, 3, 5, 8, 10], maxStops = 3
Output: [2, 3, 5]
Explanation: The shortest route with a maximum of 3 stops is to deliver to the points 2, 3, and 5.
Example 2:
Input: deliveryPoints = [1, 4, 6, 7], maxStops = 2
Output: [1, 4]
Explanation: The shortest route with a maximum of 2 stops is to deliver to the points 1 and 4.
Constraints:
  • 1 <= len(deliveryPoints) <= 100

  • 1 <= deliveryPoints[i] <= 10^6

  • 1 <= maxStops <= len(deliveryPoints)
coding Medium heap #6

6. Heap — Finding the k most frequent items

1. Background: In the context of Instacart, understanding customer purchasing behavior can help optimize inventory management and promotional strategies. Identifying the k most frequently ordered items allows Instacart to focus its marketing efforts.
2. Problem statement: Given a list of 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.
3. Function/class signature:
- def top_k_frequent(items: List[str], k: int) -> List[str]:
4. Example 1:
- Input: items = ['apple', 'banana', 'apple', 'orange', 'banana', 'banana'], k = 2
- Output: ['banana', 'apple']
- Explanation: 'banana' appears 3 times, and 'apple' appears 2 times.
5. Example 2:
- Input: items = ['carrot', 'carrot', 'potato', 'onion', 'carrot', 'potato'], k = 1
- Output: ['carrot']
6. Constraints:
- 1 <= len(items) <= 10^4
- 1 <= k <= len(items)
coding Medium sliding window #7

7. Sliding Window — Find the longest consecutive grocery items in an order

Background: Instacart needs to optimize the shopping experience by identifying longer lists of consecutive items in a user's cart, which may indicate a trend or spike in demand for certain food categories. This will aid in inventory management and promotional strategies.
Problem statement: Given an array of integers representing grocery item IDs in a shopping cart, find the maximum length of a subarray where the IDs are consecutive. The IDs can be in any order for the length of the subarray to be considered valid.
Function/class signature:
  • def longest_consecutive_items(items: List[int]) -> int:

Example 1:
Input: [1, 3, 2, 4, 5]
Output: 5
Explanation: The IDs 1, 2, 3, 4, 5 form a consecutive subarray.
Example 2:
Input: [10, 2, 3, 11, 4, 5, 1]
Output: 5
Explanation: The IDs 1, 2, 3, 4, 5 form a consecutive subarray.
Constraints:
  • 1 <= len(items) <= 1000

  • Each item ID is a positive integer up to 10^6.
system design Medium binary search #8

8. Design RetailerCatalogHistory — a timestamped store for retailer-specific product availability


Background
Instacart displays retailer-specific prices and availability, and investigating a historical shopping session requires knowing what catalog state was visible at a particular time. Implement an in-memory class that models this historical lookup. This exercise adapts the timestamped key-value store reported in an Instacart interview; the catalog schema, expiration rules, and listing API are extensions for this practice problem.
Requirements
1. Identify a product by (retailer_id, sku). Store timestamped versions containing a price in integer cents and an available quantity. Different retailers may have different versions of the same SKU.
2. Accept mutations in any timestamp order. A mutation at an existing timestamp replaces the previous mutation at that timestamp, including a deletion. Mutations affect subsequent queries immediately; queries are evaluated against the currently stored history.
3. A lookup at 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.
4. A product version may have a positive time-to-live. A version written at 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.
5. Deleting a product records a timestamped tombstone rather than erasing its history. A deletion remains effective until superseded by a later mutation. An out-of-order write before the tombstone does not resurrect the product after the deletion timestamp.
6. Listing a retailer's available products returns the visible versions whose quantity is greater than zero, sorted by SKU in ascending lexicographic order. Returned snapshots must be immutable or detached from internal state.
Class API
  • 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.


Example 1:
Input sequence:
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)

Output for the four queries, with snapshots serialized as JSON:
[
  {"sku": "milk", "price_cents": 499, "quantity": 6},
  {"sku": "milk", "price_cents": 549, "quantity": 2},
  null,
  null
]

Explanation: At time 19, the mutation at 10 is selected. At time 24, the mutation at 20 is selected and has not expired. Its expiration boundary is 20 + 5 = 25, so the lookup at 25 returns null without reviving the version at 10. No version exists at time 9.
Example 2:
Input sequence:
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)

Output for the four queries:
[
  [
    {"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}
]

Explanation: The out-of-order write at 20 is visible at 25, but the tombstone at 30 initially hides milk at 35. Writing a product at timestamp 30 replaces that tombstone. Bread is excluded from listings because its quantity is zero. Retailer r2 is independent.
Constraints
  • At most 100,000 total method calls and 100,000 distinct product keys; at most 2,000 distinct mutation timestamps per product key.

  • Retailer IDs and SKUs are nonempty ASCII strings of length at most 64; all inputs satisfy the documented bounds.

  • Timestamps and query times are integer seconds in [0, 10^12]; prices and quantities are integers in [0, 10^9]; TTL is either absent or an integer in [1, 10^9].

  • Execution is single-threaded. No persistence, networking, historical pruning, or real wall-clock access is required.

  • Point lookups must use logarithmic search within a product's history. Out-of-order insertion may take linear time in that history; listing may inspect every known SKU for the requested retailer.

Start practicing Instacart questions

Sign up for free to access walkthroughs, AI-generated questions, and more.

Get Started Free