Fastest Instamart Fulfilment From One or Two Dark Stores

Last updated: November 29, 2026

Quick Overview

Given a directed road graph with travel minutes, a rider location, a customer location, and dark stores each holding a set of SKUs, find the fastest route that collects the whole cart, either from one store or by visiting two stores in sequence, and return its time and store order.

Swiggy
Coding & Algorithms
Software Engineer
Swiggy
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given a directed road graph with travel minutes, a rider location, a customer location, and dark stores each holding a set of SKUs, find the fastest route that collects the whole cart, either from one store or by visiting two stores in sequence, and return its time and store order.

Instamart promises deliveries in minutes, and when one dark store is out of an item the platform must decide whether a split pickup still meets the promise. This Hard onsite question checks shortest paths on directed graphs, the reverse-graph trick, bitmask coverage and pruning.

What the Interviewer Expects
  • Runs Dijkstra from the rider and Dijkstra on the reversed graph from the customer
  • Encodes store coverage as bitmasks over the cart
  • Considers single-store and ordered two-store routes
  • Prunes first stores whose rider distance already exceeds the best answer
  • States complexity in terms of stores, nodes and edges
  • Returns no route when the cart cannot be covered
Key Topics to Cover
Dijkstra
reverse graph
bitmask
pruning
quick commerce routing
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 extend this to up to three stores without the cost exploding?
  • Travel times change with traffic every few minutes. What would you cache?
  • How would you trade a slightly slower route for better inventory balance across stores?
  • What if the rider must also return to a home store after delivery?
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

Edges are directed (u, v, minutes) with non-negative weights. Each store node has a SKU set; the cart is a small set (say at most 20 SKUs). Allowed routes: rider to s then customer, or rider to s1 t...

High-Level Design
  1. Bitmask each store's SKUs restricted to the cart; drop stores with nothing relevant.
  2. Dijkstra from the rider gives dist(rider, x).
  3. Dijkstra from the customer on the reversed graph gives `di...

Submit Your Answer
Markdown supported

Related Questions