-
-
Save jalasem/75c500dd0857e4c9433616bbca883131 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static long carParkingRoof(List<Long> cars, int k) { | |
// Write your code here | |
if (cars.size() == 0 || k < 0) { | |
return 0; | |
} | |
Collections.sort(cars); | |
long minDist = Long.MAX_VALUE; | |
for (int i = 0; i <= cars.size() - k; i++) { | |
minDist = Math.min(minDist, cars.get(i + k - 1) - cars.get(i)); | |
} | |
return minDist + 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment