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.*;publicclassSolution{publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Scannersc=newScanner(System.in);inttotalnumberOfStudents=sc.nextInt();List<HashMap<String,String>>listOfMap=newArrayList<>();sc.nextLine();for(inti=1;i<=totalnumberOfStudents;i++){HashMap<String,String>map=newHashMap<>();StringstudentDetails=sc.nextLine();String[]studentDetailsArr=studentDetails.split(" ");map.put("id",studentDetailsArr[0]);map.put("Name",studentDetailsArr[1]);map.put("cgpa",studentDetailsArr[2]);listOfMap.add(map);}listOfMap.sort(Comparator.comparingDouble((Map<String,String>item)->Double.parseDouble(item.get("cgpa"))).reversed().thenComparing((Map<String,String>item)->item.get("Name")).thenComparing((Map<String,String>item)->Integer.parseInt(item.get("id"))));for(Map<String,String>names:listOfMap){System.out.println(names.get("Name"));}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Java Sort
You are viewing a single comment's thread. Return to all comments →