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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Java
  3. Data Structures
  4. Java Priority Queue
  5. Discussions

Java Priority Queue

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • vitorlany
    3 months ago+ 2 comments

    To be honest, i have no idea why thats not working 😅

    class Priorities {
        public List<Student> getStudents(List<String> events) {
            PriorityQueue<Student> response = new PriorityQueue<>(
                Comparator.comparing(Student::getCGPA, Comparator.reverseOrder())
                        .thenComparing(Student::getName)
                        .thenComparing(Student::getID));
    
            for (String event : events) {
                if (!event.contains("ENTER")) {
                    response.poll();
                    continue;
                }
                String[] split = event.split(" ");
                Integer id = Integer.valueOf(split[3]);
                Double cgpa = Double.valueOf(split[2]);
    
                Student student = new Student(id, split[1], cgpa);
    
                response.add(student);
            }
    			
    
            return response.stream().collect(Collectors.toList());
        }
    }
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy