<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>statistics Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/statistics/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/statistics/</link>
	<description></description>
	<lastBuildDate>Fri, 07 Feb 2020 05:38:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>statistics Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/statistics/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 1093. Statistics from a Large Sample</title>
		<link>https://zxi.mytechroad.com/blog/algorithms/array/leetcode-1093-statistics-from-a-large-sample/</link>
					<comments>https://zxi.mytechroad.com/blog/algorithms/array/leetcode-1093-statistics-from-a-large-sample/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Fri, 07 Feb 2020 05:38:00 +0000</pubDate>
				<category><![CDATA[Array]]></category>
		<category><![CDATA[median]]></category>
		<category><![CDATA[medium]]></category>
		<category><![CDATA[mode]]></category>
		<category><![CDATA[statistics]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=6266</guid>

					<description><![CDATA[<p>We sampled integers between&#160;0&#160;and&#160;255, and stored the results in an array&#160;count:&#160;&#160;count[k]&#160;is the number of integers we sampled equal to&#160;k. Return the minimum, maximum, mean, median,&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/algorithms/array/leetcode-1093-statistics-from-a-large-sample/">花花酱 LeetCode 1093. Statistics from a Large Sample</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>We sampled integers between&nbsp;<code>0</code>&nbsp;and&nbsp;<code>255</code>, and stored the results in an array&nbsp;<code>count</code>:&nbsp;&nbsp;<code>count[k]</code>&nbsp;is the number of integers we sampled equal to&nbsp;<code>k</code>.</p>



<p>Return the minimum, maximum, mean, median, and mode of the sample respectively, as an array of&nbsp;<strong>floating point numbers</strong>.&nbsp; The mode is guaranteed to be unique.</p>



<p><em>(Recall that the median of a sample is:</em></p>



<ul><li><em>The middle element, if the elements of the sample were sorted and the number of elements is odd;</em></li><li><em>The average of the middle two elements, if the elements of the sample were sorted and the number of elements is even.)</em></li></ul>



<p><strong>Example 1:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> 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]
<strong>Output:</strong> [1.00000,3.00000,2.37500,2.50000,3.00000]
</pre>



<p><strong>Example 2:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> 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]
<strong>Output:</strong> [1.00000,4.00000,2.18182,2.00000,1.00000]
</pre>



<p><strong>Constraints:</strong></p>



<ol><li><code>count.length == 256</code></li><li><code>1 &lt;= sum(count) &lt;= 10^9</code></li><li>The mode of the sample that count represents is unique.</li><li>Answers within&nbsp;<code>10^-5</code>&nbsp;of the true value will be accepted as correct.</li></ol>



<h2><strong>Solution: TreeMap</strong></h2>



<p>Time complexity: O(1)<br>Space complexity: O(1)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  vector&lt;double&gt; sampleStats(vector&lt;int&gt;&amp; count) {
    int counts = 0;
    int minVal = 255;
    int maxVal = 0;
    int mode = -1;
    int modeCount = 0;
    long sum = 0;
    map&lt;int, int&gt; m;
    for (int i = 0; i &lt;= 255; ++i) {      
      if (!count[i]) continue;
      sum += static_cast&lt;long&gt;(i) * count[i];
      minVal = min(minVal, i);
      maxVal = max(maxVal, i);
      if (count[i] &gt; modeCount) {
        mode = i;
        modeCount = count[i];
      }
      m[counts += count[i]] = i;
    }
    auto it1 = m.lower_bound(counts / 2);
    double median = it1-&gt;second;    
    auto it2 = next(it1);
    if (counts % 2 == 0 &amp;&amp; it2 != m.end() &amp;&amp; it1-&gt;first == counts / 2) {  
      median = (median + it2-&gt;second) / 2;
    }
    return {minVal, maxVal, static_cast&lt;double&gt;(sum) / counts, median, mode};
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/algorithms/array/leetcode-1093-statistics-from-a-large-sample/">花花酱 LeetCode 1093. Statistics from a Large Sample</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/algorithms/array/leetcode-1093-statistics-from-a-large-sample/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
