n charging stations and n e-scooters along a street. chargers[i] is the position of station i and scooters[j] is the position of scooter j. Several stations or scooters may share a position.
Every scooter must be rolled to a station so that each station ends up with exactly one scooter. Moving a scooter by 1 in either direction costs 1.
Return the smallest total cost.chargers=[2, 8, 5], scooters=[9, 1, 4] → 3
The scooter at 1 goes to 2, the one at 4 to 5 and the one at 9 to 8: 1 + 1 + 1 = 3.
chargers=[3, 3], scooters=[1, 6] → 5
Both chargers sit at the same point: 2 + 3 = 5.
chargers=[2, 8, 5], scooters=[9, 1, 4]
3
Run checks the first 3 tests in your browser. Submit checks all 98 tests on the server, hidden ones included.