Problem 161612 · easy · Level 01 Prerequisites & Setup

Finished Within the Time

cumulative frequency · percentages · running totals · frequency tables

The results of a fun run are published as a frequency table: counts[i] is the number of runners who finished in the i-th time band (for example under 20 minutes, 20 to 25, 25 to 30, ...), in order from fastest to slowest. Runners want to know what share of the field finished in their band or faster.

Write cumulative_shares(counts) that returns a list of the same length where entry i is the percentage of all runners in bands 0 to i together. If the table holds no runners at all, every entry is 0.0. Do not round.

Examples

Input:  counts = [3, 9, 18, 12, 6, 2]
Output: [6.0, 24.0, 60.0, 84.0, 96.0, 100.0]
Explanation: there are 50 runners; 3 + 9 = 12 of them, 24%, finished in the first two bands.

Input:  counts = [0, 5, 0, 0, 3]
Output: [0.0, 62.5, 62.5, 62.5, 100.0]

Constraints

  • 1 <= len(counts) <= 10**5, every count a whole number with 0 <= count <= 10**6
  • percentages are compared with a small tolerance

Goals

  • Build cumulative counts with a running total
  • Turn cumulative counts into cumulative percentages
  • Use the last value as a check that nothing was lost
Starting Python…