Last active
May 13, 2020 19:56
-
-
Save zeitan/eb217f4100e45ed0c2590304a9a4586b 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 int calculateMaxShipment(List<Shipment> shipmentList) { | |
int highShipment = -1; | |
int counter = 0; | |
Map<Integer, Integer> hours = new TreeMap<>(); | |
for (Shipment shipment : shipmentList) { | |
hours.put(shipment.in, hours.getOrDefault(shipment.in, 0) + 1); | |
hours.put(shipment.out, hours.getOrDefault(shipment.out, 0) - 1); | |
} | |
for (Map.Entry<Integer, Integer> hourEntry : hours.entrySet()) { | |
counter += hourEntry.getValue(); | |
if (counter > highShipment) | |
highShipment = counter; | |
} | |
return highShipment; | |
} |
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 class Shipment { | |
final int in; | |
final int out; | |
public Shipment(int in, int out) { | |
this.in = in; | |
this.out = out; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment