Project · Data Structures and Algorithms (DSA) for interviews
Project: planning a parcel hub's day
The brief
Plan a day at a Nagpur parcel hub: order parcels for dispatch, find the smallest truck that ships everything in D days (binary search on the answer), find the busiest pincodes with a heap, count loading docks, give a rider the most slots (greedy), and list every way to fill a load exactly (backtracking).
Why it matters
Logistics companies, e-commerce warehouses and quick-commerce dark stores run these exact calculations every day. "Ship within D days", "meeting rooms" and "combination sum" are also some of the most common medium questions in product company interviews.
Skills you practise
- sorting with a key
- binary search on the answer
- heapq
- greedy interval scheduling
- backtracking with pruning
What you will have at the end
dispatch.py: a tested planning script for a parcel hub, with a short note above each function on why its algorithm is correct and what it costs.
How it is marked (rubric, 100 points)
| Correct resultsAll seven steps pass, including ties, empty input, equal times and repeated weights. | 40 |
|---|---|
| Right algorithmBinary search on the answer, heaps for top-k and docks, end-time greedy, and pruned backtracking. | 30 |
| Complexity statedEach function has its time and space complexity in a comment, and they are right. | 15 |
| Clean PythonClear names, small functions, days_needed reused by min_capacity. | 15 |
0/7 steps done
Step 1 of 7
Dispatch order
dispatch_order(parcels) returns the parcel ids with express (priority 1) first, then heavier parcels first, then by id.
Python's sorted() takes a key function, and tuples compare item by item. So the key (priority, -weight, id) sorts by priority, then by weight from heavy to light (the minus sign flips it), then by id to break ties.
sorted() is Timsort: O(n log n) time and O(n) space, and it never changes the original list.
Run shows what your code prints. Check runs the step's tests. Ctrl+Enter checks too.