A health centre records how many minutes each patient waited. A few very long waits pull the ordinary average (the mean: total divided by count) above the middle value (the median: the middle of the sorted data, or the mean of the two middle values for an even count). Very short waits among long ones pull it below.
Write lean(waits) that returns a tuple (mean, median, direction) where direction is
"right"if the mean is greater than the median (a long tail of large values),"left"if the mean is less than the median (a long tail of small values),"balanced"if they are exactly equal.
Examples
Input: waits = [5, 8, 6, 7, 44]
Output: (14.0, 7, "right")
Explanation: the total is 70, so the mean is 14.0; in order 5, 6, 7, 8, 44 the middle is 7.
Input: waits = [30, 2, 28, 31, 29, 30]
Output: (25.0, 29.5, "left")
Input: waits = [10, 20, 30]
Output: (20.0, 20, "balanced")
Constraints
1 <= len(waits) <= 10**5- every wait is a whole number with
0 <= wait <= 10**4 - the direction must be decided exactly: for example, a mean of
(1 + 1 + 2) / 3and a median of1differ, and the mean of[1, 2, 3, 4]equals its median
Goals
- Compute the mean and the median of the same data
- Read the shape of the data from how the two compare
- Compare two averages exactly instead of trusting floating-point equality