🚀

Thanksgiving Sale: Use Coupon Code THANKS25 to Get Extra 25% Off.

00DAYS
:
00HOURS
:
00MINUTES
:
00SECONDS

Leetcode Problem 2512. Reward Top K Students

2512. Reward Top K Students

Leetcode Solutions

Using HashMap and PriorityQueue

  1. Create a HashMap feedbackScores to store the scores for positive and negative feedback words.
  2. Populate feedbackScores with positive words having a score of 3 and negative words having a score of -1.
  3. Create a HashMap studentScores to keep track of the total score for each student.
  4. Iterate over each feedback report and update the corresponding student's score in studentScores based on the words in the report.
  5. Create a PriorityQueue studentRanking that sorts students first by their scores in non-increasing order and then by their IDs in increasing order.
  6. Add all students and their scores to studentRanking.
  7. Extract the top k students from studentRanking and add them to the result list topStudents.
  8. Return the topStudents list.
UML Thumbnail

Using HashMaps and Sorting

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...