Statistics from a 256-Bucket Frequency Array
Problem: Compute Statistics from a 256-Bucket Frequency Array
You are given a frequency array count of length 256, where count[i] represents how many times value i appears in the original data. The possible values are fixed to 0..255.
Compute the following statistics of the original data:
minimummaximummeanmedianmode- population
standard deviation
If there are multiple modes, return the smallest value.
The standard deviation is defined as:
[ std = \sqrt{\frac{\sum count[i] \times (i - mean)^2}{N}} ]
where N = sum(count).
Input Format
For testing purposes, stdin uses a sparse representation:
- The first line contains an integer
m, the number of non-zero buckets. - The next
mlines each contain two integersvalue count, meaningvalueappearscounttimes.
This is equivalent to a frequency array of length 256, with all omitted buckets having frequency 0.
Output Format
Print one line:
minimum maximum mean median mode stddev
where:
minimum,maximum, andmodeare integers;mean,median, andstddevare printed with exactly5digits after the decimal point.
Constraints
0 <= value <= 255count > 01 <= m <= 256- There is at least one data point:
sum(count) > 0 - The total frequency can be large, so do not expand the original data array.
Example
Input
3
0 2
1 5
2 8
Output
0 2 1.40000 2.00000 2 0.71181
Example
Unlock to view complete problem details
and practice with sample input/output
Was this article helpful?
View Test Cases & Run Code requires membership
Standard Input
Execution Result:
