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.
importjava.io.*;importjava.util.*;importjava.lang.*;publicclassSolution{publicstaticvoidmain(String[]args){Scannerinput=newScanner(System.in);List<AbstractMap.SimpleEntry<Integer,Integer>>entryList=newLinkedList<>();intn=input.nextInt();//Builds a list of key value pairsfor(inti=0;i<n;i++){entryList.add(newAbstractMap.SimpleEntry<Integer,Integer>(i+1,input.nextInt()+input.nextInt()));}//Sorts the list of entries according to valueCollections.sort(entryList,(p1,p2)->(p1.getValue()).compareTo(p2.getValue()));//Print the sorted list of entriesStringBuilderoutput=newStringBuilder("");for(AbstractMap.SimpleEntry<Integer,Integer>entry:entryList){output.append(entry.getKey()+" ");}System.out.println(output);}}
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 →