You are given a large sample of integers in the range [0, 255]. Since the sample is so large, it is represented by an array count&nbsp;where count[k] is the number of times that k appears in the sample.

Calculate the following statistics:


	minimum: The minimum element in the sample.
	maximum: The maximum element in the sample.
	mean: The average of the sample, calculated as the total sum of all elements divided by the total number of elements.
	median:
	
		If the sample has an odd number of elements, then the median is the middle element once the sample is sorted.
		If the sample has an even number of elements, then the median is the average of the two middle elements once the sample is sorted.
	
	
	mode: The number that appears the most in the sample. It is guaranteed to be unique.


Return the statistics of the sample as an array of floating-point numbers [minimum, maximum, mean, median, mode]. Answers within 10-5 of the actual answer will be accepted.

&nbsp;
Example 1:

Input: count = [0,1,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
Output: [1.00000,3.00000,2.37500,2.50000,3.00000]
Explanation: The sample represented by count is [1,2,2,2,3,3,3,3].
The minimum and maximum are 1 and 3 respectively.
The mean is (1+2+2+2+3+3+3+3) / 8 = 19 / 8 = 2.375.
Since the size of the sample is even, the median is the average of the two middle elements 2 and 3, which is 2.5.
The mode is 3 as it appears the most in the sample.


Example 2:

Input: count = [0,4,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
Output: [1.00000,4.00000,2.18182,2.00000,1.00000]
Explanation: The sample represented by count is [1,1,1,1,2,2,2,3,3,4,4].
The minimum and maximum are 1 and 4 respectively.
The mean is (1+1+1+1+2+2+2+3+3+4+4) / 11 = 24 / 11 = 2.18181818... (for display purposes, the output shows the rounded number 2.18182).
Since the size of the sample is odd, the median is the middle element 2.
The mode is 1 as it appears the most in the sample.


&nbsp;
Constraints:


	count.length == 256
	0 &lt;= count[i] &lt;= 109
	1 &lt;= sum(count) &lt;= 109
	The mode of the sample that count represents is unique.


class Solution(object):
    def sampleStats(self, count):
        """
        :type count: List[int]
        :rtype: List[float]
        """
        maxv,minv,acc,cnt,mode,modev=None,None,0,0.0,0,0
        for i,n in enumerate(count):
            if minv==None and n!=0:minv=i
            if n!=0:maxv=i
            if n>modev:modev,mode=n,i
            acc,cnt=acc+n*i,cnt+n
          
        midCnt,cc,midv,prei=cnt//2,0,0,i
        for i,n in enumerate(count):
            if n==0:continue
            if cc+n<=midCnt:
                cc,prei=cc+n,i
                continue
            if cnt%2==1:midv=i
            else:midv=(prei+i)/2.0 if cc==midCnt else i
            break
        return (minv,maxv,acc/cnt,midv,mode)   
class Solution {
    public double[] sampleStats(int[] count) {
        double[]ans=new double[5];
        ans[0]=-1;
        ans[1]=-1;
        int place=0;
        while(ans[0]==-1){
            if(count[place]>0)
                ans[0]=place;
            place++;
        }
        place=count.length-1;
        while(ans[1]==-1){
             if(count[place]>0)
                ans[1]=place;
            place--;
        }
        int countEl=count[0];
        int max=count[0];
        for(int i=1;i<count.length;i++){
            countEl+=count[i];
            if(count[i]>max){
                max=count[i];
                ans[4]=i;
            }
        }
        for(int i=0;i<count.length;i++){
            if(count[i]>0){
                double tmp=count[i];
                tmp/=countEl;
                ans[2]+=tmp*i;
            }
        }
        place=0;
        int whereToStop=0;
        while(whereToStop<countEl/2){
            whereToStop+=count[place];
            place++;
        }
        place--;
        if(countEl%2==1){
            if(whereToStop==countEl/2){
                place++;
                while(count[place]==0)
                    place++;
            }
                
            ans[3]=place;
        }
        else{
            double tmp=place;
            if(whereToStop==countEl/2){
                place++;
                while(count[place]==0)
                    place++;
            }
            tmp+=place;
            ans[3]=tmp/2;
        }
        return ans;
    }
}
class Solution {
public:
    vector<double> sampleStats(vector<int>& count) {
        vector<double> results;

        results.push_back(findMin(count));
        results.push_back(findMax(count));

        const int sum = std::accumulate(std::begin(count), std::end(count), 0);
        results.push_back(findMean(count, sum));

        if (sum % 2 == 0)
        {
            const auto left = findMedian(count, sum/2);
            const auto right = findMedian(count, sum/2 + 1);
            results.push_back ((left + right) / 2.0);
        }
        else
            results.push_back(findMedian(count, sum/2 + 1));

        results.push_back(findMode(count));

        return results;
    }
    
private:
    int findMin(const vector<int> &count) {
        const auto minPtr = std::find_if(std::begin(count), std::end(count), 
                                         [](const int& c) { return c > 0; });

        return minPtr - std::begin(count);
    }

    int findMax(const vector<int> &count) {
        const auto maxPtr = std::find_if(std::rbegin(count), std::rend(count), 
                                         [](const int& c) { return c > 0; });

        return (std::rend(count) - 1) - maxPtr;
    }

    int findMode(const vector<int> &count) {
    
        const auto maxCountPtr = std::max_element(begin(count), end(count));

        return maxCountPtr - std::begin(count);
    }

    double findMean(const vector<int> &count, const int &sum) {
        auto ratio = 1.0 / sum;
        auto mean = 0.0;

        for (int i = 0; i < count.size(); ++i)
            mean += count[i] * ratio * i;

        return mean;
    }

    int findMedian(const vector<int> &count, int medianCount) {
        for (int i = 0; i < count.size(); ++i)
            if (count[i] < medianCount)
                medianCount -= count[i];
        else
            return i;
        
        return -1;
    }
};
/**
 * @param {number[]} count
 * @return {number[]}
 */
var sampleStats = function(count) {
    let min;
    let max;
    let sum = 0;
    let mode = 0;
    let prefix = 0;
    let prefixSum = new Map();
    for (let i=0; i<count.length; i++) {
        if (count[i] === 0) continue;
        if (min === undefined) min = i;
        max = i;
        if (count[i] > count[mode]) mode = i;
        sum += (count[i] * i);
        prefix += count[i];
        prefixSum.set(prefix, i);
    }
    const mean = sum / prefix;
    // min, max, mean, mode found
    // finding median using prefixSum map
    let median;
    let medianLeft;
    let medianRight;
    const medianPoint = Math.ceil(prefix/2);
    for (let i=medianPoint; i<=prefix; i++) {
        if (!prefixSum.has(i)) continue;
        if (medianLeft !== undefined) {
            medianRight = prefixSum.get(i);
            median = (medianLeft+medianRight) / 2;
            break;
        }
        if (i === medianPoint && prefix % 2 === 0) {
            medianLeft = prefixSum.get(i);
            continue;
        }
        median = prefixSum.get(i);
        break;
    }

    return [min, max, mean, median, mode];
};
Statistics from a Large Sample