You are viewing a single comment's thread. Return to all comments →
Here is my Java 15 solution:
import java.util.*; import java.util.stream.*; class Result { private static HashMap<Integer, Integer> createOrderMap(int[][] orders) { HashMap<Integer, Integer> map = new HashMap<>(); for (int i = 0; i < orders.length; i++) { int customerNumber = i + 1; int deliverTime = orders[i][0] + orders[i][1]; map.put(customerNumber, deliverTime); } return map; } public static List<Integer> jimOrders(int[][] orders) { Map<Integer, Integer> orderMap = createOrderMap(orders); return orderMap.entrySet().stream() .sorted(Map.Entry.comparingByValue()) .map(Map.Entry::getKey) .collect(Collectors.toList()); } } public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int[][] array = new int[n][2]; for (int i = 0; i < n; i++) { int orderNumber = scanner.nextInt(); int preparationTime = scanner.nextInt(); int[] orderPreparationArray = { orderNumber, preparationTime }; array[i] = orderPreparationArray; } scanner.close(); List<Integer> result = Result.jimOrders(array); result.forEach(element -> System.out.print(element + " ")); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Jim and the Orders
You are viewing a single comment's thread. Return to all comments →
Here is my Java 15 solution: