We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
My Java solution with o(n log n) time and o(n) space:
publicstaticList<Integer>jimOrders(List<List<Integer>>orders){List<int[]>indexedOrders=newArrayList<>();//holds order idxs and their times//get the times for each order idxfor(inti=0;i<orders.size();i++){inttime=orders.get(i).get(0)+orders.get(i).get(1);indexedOrders.add(newint[]{i+1,time});}//sort orders ascending to earliest ordersindexedOrders.sort(Comparator.comparingInt(o->o[1]));//return list of only the order idxsreturnindexedOrders.stream().map(o->o[0]).collect(Collectors.toList());}
Cookie support is required to access HackerRank
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 →
My Java solution with o(n log n) time and o(n) space: