buckets
, where each list corresponds to a possible Manhattan distance from 0 to 1998.(worker index, bike index)
pair to the corresponding bucket.answer
, to store the bike assigned to each worker, and a set, assignedBikes
, to keep track of which bikes have been assigned.buckets
array from the smallest distance to the largest.
a. For each bucket, iterate over the (worker, bike)
pairs.
b. If the worker has not been assigned a bike and the bike has not been assigned, assign the bike to the worker, add the bike to assignedBikes
, and update answer
.answer
array.