Find the Nearest Open Pickup Slot After a Requested Time
Last updated: November 29, 2026
Quick Overview
A store offers grocery pickup slots, each with fixed capacity. Implement book(requested_time), which reserves the earliest slot starting at or after the requested time that still has room, and cancel(slot), which releases one reservation.
Walmart Labs
November 29, 20260
0
0 solved
A store offers grocery pickup slots, each with fixed capacity. Implement book(requested_time), which reserves the earliest slot starting at or after the requested time that still has room, and cancel(slot), which releases one reservation.
Online grocery pickup and delivery slot booking is a core Walmart product, and the slot picker must answer fast under heavy evening demand. Walmart Labs phone screens use this to check whether you keep an ordered set of open slots and update it correctly as slots fill and free up.
What the Interviewer Expects
- Keep only slots with remaining capacity in a sorted structure
- Use binary search for the successor query
- Remove a slot when it fills and reinsert it on cancel
- Discuss the cost of list insertion versus a balanced tree
- Handle requests after the last slot
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you support a customer preference for the closest slot before or after the requested time?
- How would you make booking safe when many app servers book the same store concurrently?
- What changes if slot capacity depends on the number of associates scheduled?
- How would you hold a slot for ten minutes while the customer checks out?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Slots are identified by start minute. Each has the same starting capacity. book(t) returns the slot it reserved, or None if nothing at or after t has room. cancel(slot) gives one unit back. Calls ...
High-Level Design
Keep a dict of remaining capacity per slot and a sorted list open of slots with capacity above zero. A booking is a successor query: bisect_left(open, t) finds the first open slot at or after t. W...