bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1086. High Five

1086. High Five

Leetcode Solutions

Approach: Using Map and Min Heap

  1. Initialize a map where each key is a student ID and each value is a min heap (or priority queue) that will store up to five scores.
  2. Iterate over the list of items.
  3. For each item, check if the student ID already has a min heap in the map.
  4. If not, create a new min heap for that ID.
  5. Add the score to the min heap for the corresponding student ID.
  6. If the min heap size exceeds five, remove the smallest score (min heap root).
  7. After processing all items, iterate over the map entries.
  8. For each entry, calculate the average of the scores in the min heap using integer division.
  9. Add the student ID and the calculated average to the result list.
  10. Sort the result list by student ID.
  11. Return the sorted result list.
UML Thumbnail

Approach: Using Sorting

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...