Instacart logo

Instacart Software Engineer Coding Questions

14 practice questions for Instacart Software Engineer 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 Hard Verified Question #2

2. Minimum Workers For Average Task Time


Category: Algorithm coding problem
A manufacturing plant has workers processing jobs. Each job has a processingTime and an arrivalTime. Workers process one job at a time. When a...
Input: List
Output: Integer
coding Medium Verified Question #3

3. 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 Hard Verified Question #4

4. Analytics Pivot Query


Category: Graph coding problem
An e-commerce analytics platform stores transaction records in a data warehouse. Each record contains at least the columns transaction_id, cost,...
Input: Graph (nodes and edges)
Output: Computed result
coding Medium Verified Question #5

5. Config Chain Resolver


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

1. [Caching] — Query an out-of-order timestamped cache with expiration and deletions


Background
Instacart's storefront needs retailer-specific product information, including prices and availability. A timestamped cache can support historical debugging when updates arrive late or are corrected; this exercise models that requirement rather than claiming to reproduce Instacart's production architecture.
Problem statement
Implement an online timestamped key-value cache. Each key has a history of versions indexed by an integer timestamp. Calls may arrive in any order, including writes whose timestamps are earlier than previously inserted versions. You cannot inspect future calls or preprocess the complete operation sequence.
A set operation inserts a value at a timestamp, optionally with a time-to-live. A delete operation inserts a tombstone at a timestamp; it does not physically remove older versions. Either operation replaces any existing version for the same key at exactly the same timestamp.
For get(key, timestamp), first find the version with the greatest timestamp less than or equal to the query timestamp:
  • If no such version exists, return null.

  • If that version is a tombstone, return null.

  • If it is a value written at time s with TTL d, return the value only when timestamp < s + d. The expiration boundary is exclusive.

  • Otherwise, return its value.


An expired version or tombstone never causes an older value to reappear. A later version can make the key available again. Late writes change the results of subsequent historical queries; previously returned answers are not revised.
Support each public operation in expected O(log(v + 1)) time or better, where v is the number of distinct timestamps stored for that key. Use O(N) total space for N stored versions. A sorted array with linear-time insertion does not meet the requirement. Implement the ordered structure yourself using only the language's standard library.
Function or class signature
  • TimestampedCache() — construct an empty cache.

  • set(key: str, value: str, timestamp: int, ttl: int | None = None) -> None — insert or replace a value version; None means no expiration.

  • delete(key: str, timestamp: int) -> None — insert or replace a tombstone, even if the key has never been written.

  • get(key: str, timestamp: int) -> str | None — retrieve the value using the rules above.


Example 1:
Input:
{
  "operations": [
    ["set", "retailer17:milk:price", "4.99", 20, null],
    ["set", "retailer17:milk:price", "4.49", 10, 5],
    ["get", "retailer17:milk:price", 9],
    ["get", "retailer17:milk:price", 12],
    ["get", "retailer17:milk:price", 15],
    ["get", "retailer17:milk:price", 25],
    ["set", "retailer17:milk:price", "4.79", 14, null],
    ["get", "retailer17:milk:price", 15]
  ]
}

Output:
[null, null, null, "4.49", null, "4.99", null, "4.79"]

Explanation: The value at time 10 expires at 10 + 5 = 15. The version at time 20 does not apply to earlier queries. After a late write at time 14, the query at time 15 selects that new historical version instead. Outputs for writes are null.
Example 2:
Input:
{
  "operations": [
    ["set", "retailer17:eggs:availability", "in_stock", 5, null],
    ["delete", "retailer17:eggs:availability", 12],
    ["get", "retailer17:eggs:availability", 11],
    ["get", "retailer17:eggs:availability", 12],
    ["set", "retailer17:eggs:availability", "limited", 12, 3],
    ["get", "retailer17:eggs:availability", 14],
    ["get", "retailer17:eggs:availability", 15],
    ["set", "retailer17:eggs:availability", "in_stock", 18, null],
    ["get", "retailer17:eggs:availability", 18]
  ]
}

Output:
[null, null, "in_stock", null, null, "limited", null, null, "in_stock"]

Explanation: The write at time 12 replaces the tombstone at the same timestamp. Its value expires at 12 + 3 = 15; the older unlimited-lifetime value at time 5 does not reappear. The version at time 18 restores availability.
Constraints:
  • At most 200,000 public method calls; at most 200,000 distinct stored versions across all keys.

  • Keys and values are strings of length 1 through 100; values are never null.

  • 0 <= timestamp <= 10^12.

  • TTL is either None or an integer satisfying 1 <= ttl <= 10^12.

  • Operations are single-threaded. Historical queries may use any valid timestamp, including times earlier than all writes or later than all writes.


Follow-up:
Add compact(cutoff: int) -> None. After compaction, queries and writes earlier than cutoff are forbidden, but all permitted future operations must behave exactly as before. Which version preceding the cutoff must be retained, and how would you remove older nodes efficiently?
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 hash map #2

2. 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.
coding Medium dynamic programming #3

3. 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 #4

4. 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 #5

5. [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 #6

6. 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 #7

7. 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 #8

8. 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.

Related Instacart Software Engineer interview prep

Start practicing Instacart questions

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

Get Started Free