Ctrl K

Summary From a Tally Sheet

Medium
A sample consists of integers from 0 to len(tally) - 1, but it is huge, so it is stored as a tally sheet: tally[v] is how many times the number v appears in the sample. Return a list of five numbers [minimum, maximum, mean, median, mode]: - **minimum** and **maximum** are the smallest and largest numbers in the sample; - **mean** is the sum of all numbers divided by how many there are; - **median** is the middle element of the sorted sample, or the average of the two middle elements when the count is even; - **mode** is the number that appears most often (it is guaranteed to be unique). Answers within 10⁻⁵ of the true value are accepted.
Example 1
tally=[0, 0, 2, 0, 5, 1] → [2, 5, 3.625, 4.0, 4]

The sample is 2, 2, 4, 4, 4, 4, 4, 5. Minimum 2, maximum 5, mean 29 / 8 = 3.625, the median is the average of the 4th and 5th values, which is 4, and the mode is 4.

Example 2
tally=[3, 1, 0, 0, 0, 0, 0, 1] → [0, 7, 1.6, 0, 0]

The sample is 0, 0, 0, 1, 7. The mean is 8 / 5 = 1.6, the median is the third value, 0, and the mode is 0.

Constraints
  • 1 ≤ len(tally) ≤ 1000
  • 0 ≤ tally[v] ≤ 10⁹
  • 1 ≤ sum of tally ≤ 10⁹
  • The most frequent number is unique
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsOdds of Exactly That Many Heads MediumA Fair Split of Colored Beads HardTurn a Square Clockwise MediumPostfix Calculator MediumRoll an Array to the Right Medium
loading Python…
Input
tally=[0, 0, 2, 0, 5, 1]
Expected
[2, 5, 3.625, 4.0, 4]

Run checks the first 3 tests in your browser. Submit checks all 9 tests on the server, hidden ones included.