Skip to content

Instantly share code, notes, and snippets.

@zeitan
Last active May 13, 2020 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeitan/eb217f4100e45ed0c2590304a9a4586b to your computer and use it in GitHub Desktop.
Save zeitan/eb217f4100e45ed0c2590304a9a4586b to your computer and use it in GitHub Desktop.
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;
}
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