Pick the Best Courier for Each Delivery Zone
Problem
A food-delivery company assigns one courier to each delivery zone. Two DataFrames are loaded from CSV: `couriers` (`courier_id`, `capability`, `skill_level`) lists each courier's vehicle capabilities and skill level, and `zones` (`zone_id`, `capability`, `needed_level`) lists the capabilities a zone requires and how critical each is (level 1 to 5).
A courier is eligible for a zone only if they possess every capability the zone requires. For each eligible courier compute a `fit_score` that starts at 100, adds 10 for every capability where the courier's skill_level is strictly greater than the zone's needed level, and subtracts 5 for every capability where the courier's skill_level is strictly less. For each zone return the courier with the highest fit_score, breaking ties by the smaller courier_id. Return a DataFrame with columns `zone_id`, `courier_id`, `fit_score`, ordered by `zone_id`.
Input data
Example rows — the live problem includes the full dataset.
| courier_id | capability | skill_level |
|---|---|---|
| 701 | cold_chain | 5 |
| 701 | bike | 3 |
| 701 | cash_handling | 4 |
| 702 | cold_chain | 4 |
| 702 | bike | 5 |
| zone_id | capability | needed_level |
|---|---|---|
| 40 | cold_chain | 4 |
| 40 | bike | 3 |
| 40 | cash_handling | 5 |
| 41 | cold_chain | 3 |
| 41 | bike | 4 |
Expected output
Your answer should return 2 rows with the columns zone_id, courier_id, fit_score.
Starter code (Pandas (Python))
import pandas as pd
def best_courier(couriers, zones) -> pd.DataFrame:
# Your code here
return couriersSolve this Pandas question free
Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock