File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
implement-laptop-allocation Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -44,11 +44,16 @@ def allocate_laptops(people: List[Person], laptops: List[Laptop]) -> Dict[Person
4444 for person , laptop in zip (people , scenario ):
4545 total_sadness += sadness (person , laptop )
4646
47- #Check if this is the best scenario so far
47+ #Implement early break if total is already worse than best
48+ if total_sadness >= best_total_sadness :
49+ break
50+
51+ # Check if this scenario is better
4852 if total_sadness < best_total_sadness :
49- best_total_sadness = total_sadness
50- best_scenario_assignment = scenario
53+ best_total_sadness = total_sadness
54+ best_scenario_assignment = scenario
5155
56+
5257 # Convert best_scenario_assignment into Dict[Person, Laptop]
5358 return {person : laptop for person , laptop in zip (people , best_scenario_assignment )}
5459
You can’t perform that action at this time.
0 commit comments