Ezvor

1057. Campus Bikes

MediumArray Preparing judge… LeetCode
ArraySortingHeap (Priority Queue)

Hints

Hint 1

Sort the elements by distance. In case of a tie, sort them by the index of the worker. After that, if there are still ties, sort them by the index of the bike.

Can you do this in less than O(nlogn) time, where n is the total number of pairs between workers and bikes?

Hint 2
Loop the sorted elements and match each pair of worker and bike if the given worker and bike where not used.