Leetcode Problem 571. Find Median Given Frequency of Numbers

571. Find Median Given Frequency of Numbers

Leetcode Solutions

Calculating Median with Cumulative Frequency

  1. Calculate the cumulative frequency for each number in ascending order using the SUM() OVER() window function.
  2. Determine the total sum of frequencies and calculate the median position(s).
  3. Identify the number(s) whose cumulative frequency range includes the median position(s).
  4. If there is one number in the median position, that number is the median.
  5. If there are two numbers in the median positions, calculate the average of these two numbers to find the median.
  6. Round the median to one decimal point as required.

erDiagram
    Numbers {
        int num PK
        int frequency
    }

Nothing

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...