Leetcode Problem 1792. Maximum Average Pass Ratio

1792. Maximum Average Pass Ratio

Leetcode Solutions

Greedy Approach with Max Heap

  1. Initialize a max heap to store pairs of delta and class index.
  2. Calculate the initial delta for each class and add it to the heap.
  3. While there are extra students: a. Extract the class with the maximum delta from the heap. b. Assign an extra student to this class. c. Recalculate the delta for this class. d. Add the updated class back to the heap.
  4. After all extra students are assigned, calculate the final average pass ratio.
UML Thumbnail

Brute Force Approach with Iterative Student Assignment

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...