Assign Incoming Orders to the First Free Fulfillment Lane

Last updated: November 29, 2026

Quick Overview

Orders arrive in time order, each with a processing duration. Assign each order to the free lane with the smallest id; if no lane is free, the order waits for whichever lane frees up first. Return the lane each order uses.

Walmart Labs
Coding & Algorithms
Software Engineer
Walmart Labs
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Medium

0

0

0 solved


Orders arrive in time order, each with a processing duration. Assign each order to the free lane with the smallest id; if no lane is free, the order waits for whichever lane frees up first. Return the lane each order uses.

Inspired by Walmart fulfillment centers, where orders are routed to packing lanes as they free up. This style of two-heap simulation is common in Walmart Labs online assessments, and the grader checks correct tie-breaking and that waiting orders start when the lane frees, not when they arrived.

What the Interviewer Expects
  • Use a min-heap of free lanes keyed by id
  • Use a min-heap of busy lanes keyed by free time then id
  • Release every lane whose free time has passed before assigning
  • Start a waiting order at its lane's free time
  • Achieve O(n log k) time
Key Topics to Cover
heaps
simulation
scheduling
priority queues
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 also report the average wait time per order?
  • What if lanes have different speeds?
  • How would you handle priority orders that jump ahead of waiting ones?
  • What changes if orders do not arrive sorted by time?
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: k lanes with ids 0 to k-1 and a list of (arrival, duration) sorted by arrival. A lane is free at time t if its last order finished at or before t. Rule: pick the free lane with the smallest i...

High-Level Design

Two heaps. free holds idle lane ids. busy holds (free_at, lane). Before assigning an order, move every lane with free_at <= arrival from busy back to free. If free is non-empty, pop the smalle...


Submit Your Answer
Markdown supported