Analyze Mission Outcomes and Allocate Response Units
Capital OneData Analyst · Online AssessmentLast updated
Analyze incident response records to calculate unit win rates, evaluate the impact of rest periods on success, and rank response units using tie-breakers.
Problem Statement
You are tasked with evaluating the operational performance of emergency response units across fleet dispatch missions. Management wants to understand unit reliability and determine the optimal unit to prioritize for critical missions.
Write a function evaluate_and_allocate_units(missions, units, min_missions) that processes historical mission data and returns a structured operational summary.
Requirements
-
Eligible Win Rates:
- Calculate the success rate (successful missions / total missions) for each unit that has participated in at least
min_missionsmissions. - Round the rate to 3 decimal places.
- Calculate the success rate (successful missions / total missions) for each unit that has participated in at least
-
Rest Period Analysis:
- Classify each mission as either
"well_rested"(rest_days >= 3) or"fatigued"(rest_days < 3). - Compute the aggregate success rate for each group across all missions. Round to 3 decimal places. If a group has zero missions, its rate should be
None.
- Classify each mission as either
-
Unit Allocation Recommendation:
- Identify the single best eligible unit (
top_unit_id) to deploy. - Rank units by:
- Highest win rate (descending).
- Lowest average
damage_costacross all their missions (ascending). - Smallest
unit_id(ascending) in case of a tie.
- If no units meet the
min_missionsthreshold,top_unit_idshould beNone.
- Identify the single best eligible unit (
Function Signature
def evaluate_and_allocate_units(
missions: list[dict],
units: list[dict],
min_missions: int
) -> dict:
pass
Input Format
missions: List of dictionaries, each containing:"mission_id"(int)"unit_id"(int)"success"(bool)"damage_cost"(float)"rest_days"(int)
units: List of dictionaries containing"unit_id"(int) and"unit_name"(str).min_missions: Integer threshold for evaluation eligibility.
Output Format
Return a dictionary with the following shape:
{
"win_rates": {unit_id: win_rate, ...}, # Only for units with >= min_missions
"rest_comparison": {
"well_rested_rate": float or None,
"fatigued_rate": float or None
},
"top_unit_id": int or None
}
Example
missions = [
{"mission_id": 1, "unit_id": 101, "success": True, "damage_cost": 500.0, "rest_days": 4},
{"mission_id": 2, "unit_id": 101, "success": False, "damage_cost": 1200.0, "rest_days": 1},
{"mission_id": 3, "unit_id": 102, "success": True, "damage_cost": 200.0, "rest_days": 3},
{"mission_id": 4, "unit_id": 102, "success": True, "damage_cost": 400.0, "rest_days": 2},
]
units = [
{"unit_id": 101, "unit_name": "Alpha"},
{"unit_id": 102, "unit_name": "Bravo"}
]
min_missions = 2
# Output:
# {
# "win_rates": {101: 0.5, 102: 1.0},
# "rest_comparison": {
# "well_rested_rate": 1.0, # missions 1 and 3: 2/2 = 1.0
# "fatigued_rate": 0.5 # missions 2 and 4: 1/2 = 0.5
# },
# "top_unit_id": 102
# }
Hints
Hint 1
Aggregate missions by unit_id first to compute count, total successes, and total damage costs in a single pass.
Hint 2
For the rest analysis, maintain counters for missions with rest_days >= 3 versus rest_days < 3 across the entire dataset.
Hint 3
When sorting eligible units for the allocation recommendation, use a multi-key tuple like (-win_rate, avg_damage, unit_id).
Follow-up questions
- How would you rewrite this aggregation logic in SQL using window functions and conditional aggregation?
- If sample sizes vary significantly (e.g., 5 missions vs. 500 missions), how could you use empirical Bayes or Wilson score intervals to adjust win rates for uncertainty?
- How would you extend this logic to handle real-time dispatch where unit availability and travel distance are dynamic constraints?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.