Merge Courier Serviceable Pincode Ranges And Answer Lookups
Last updated: November 29, 2026
Quick Overview
Each courier partner publishes overlapping and adjacent inclusive pincode ranges it can deliver to. Build a structure that merges each courier's ranges and then answers which couriers can serve a given pincode, efficiently for many lookups.
Meesho
November 29, 20260
0
0 solved
Each courier partner publishes overlapping and adjacent inclusive pincode ranges it can deliver to. Build a structure that merges each courier's ranges and then answers which couriers can serve a given pincode, efficiently for many lookups.
Every Meesho product page and checkout has to answer whether an order can reach the buyer's pincode and through which logistics partner, at very high QPS. The interviewer checks interval merging, binary search over sorted starts, and the trade-off between preprocessing and query time.
What the Interviewer Expects
- Sorts and merges intervals, treating adjacent pincodes as contiguous
- Uses bisect on sorted starts for O(log m) lookups
- Keeps per-courier indexes separate
- Discusses the per-query cost across many couriers
- Considers a precomputed pincode-to-couriers table given the small pincode space
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
- India has about 19,000 active pincodes. Would you still use intervals?
- Couriers update ranges daily. How do you swap the index without downtime?
- How would you also return the promised delivery days per courier?
- How would you choose a courier when several serve the pincode?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: courier_ranges, a dict courier -> list of (lo, hi) inclusive ranges, possibly overlapping or touching ((560021, 560030) right after (560005, 560020)). Queries: couriers_for(pincode) r...
High-Level Design
- Per courier, sort ranges and merge when
lo <= last_hi + 1(the+1joins adjacent pincodes, which matter since pincodes are integers). - Store merged starts and ends as two parallel lists.
- F...