Minimum Shoppers Needed to Cover Overlapping Delivery Windows

Last updated: November 29, 2026

Quick Overview

Given a list of shopping jobs, each with a start and end minute, return the minimum number of shoppers needed so that no shopper works two overlapping jobs. Then return an actual assignment of jobs to shopper ids.

Instacart
Coding & Algorithms
Software Engineer
Instacart
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Medium

0

0

0 solved


Given a list of shopping jobs, each with a start and end minute, return the minimum number of shoppers needed so that no shopper works two overlapping jobs. Then return an actual assignment of jobs to shopper ids.

Instacart phone screens often wrap a classic pattern in marketplace language, here staffing shoppers against delivery windows. The interviewer checks whether you recognize the sweep line, handle back-to-back jobs correctly, and can extend the count into a real assignment.

What the Interviewer Expects
  • Treat windows as half-open so a job ending at 30 frees the shopper for one starting at 30
  • Count peak concurrency with a sorted event sweep in O(n log n)
  • Produce an assignment with a min-heap of shopper free times
  • Ignore or reject zero-length and inverted windows explicitly
  • Explain why the greedy assignment uses exactly the peak count
Key Topics to Cover
sweep line
intervals
min-heap
greedy assignment
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you add a 10 minute travel buffer between consecutive jobs?
  • What changes if shoppers have different shift start and end times?
  • How would you answer this for a live stream of jobs arriving through the day?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input is a list of (start, end) pairs in minutes. A shopper can take a new job the moment the previous one ends, so intervals are half-open [start, end). Output 1: the peak number of simultaneous ...

High-Level Design

The minimum number of shoppers equals the maximum number of jobs active at one instant: you clearly need that many, and the greedy below never needs more. For the count, turn each job into a +1 event ...


Submit Your Answer
Markdown supported

Related Questions