|
| 1 | +<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> |
| 2 | +<!--+----------------------------------------------------------------------+--> |
| 3 | +<!--|@author Openset <openset.wang@gmail.com> |--> |
| 4 | +<!--|@link https://github.com/openset |--> |
| 5 | +<!--|@home https://github.com/openset/leetcode |--> |
| 6 | +<!--+----------------------------------------------------------------------+--> |
| 7 | + |
| 8 | +[< Previous](https://github.com/openset/leetcode/tree/master/problems/shortest-common-supersequence "Shortest Common Supersequence") |
| 9 | + |
| 10 | +[Next >](https://github.com/openset/leetcode/tree/master/problems/car-pooling "Car Pooling") |
| 11 | + |
| 12 | +## 1093. Statistics from a Large Sample (Medium) |
| 13 | + |
| 14 | +<p>We sampled integers between <code>0</code> and <code>255</code>, and stored the results in an array <code>count</code>: <code>count[k]</code> is the number of integers we sampled equal to <code>k</code>.</p> |
| 15 | + |
| 16 | +<p>Return the minimum, maximum, mean, median, and mode of the sample respectively, as an array of <strong>floating point numbers</strong>. The mode is guaranteed to be unique.</p> |
| 17 | + |
| 18 | +<p><em>(Recall that the median of a sample is:</em></p> |
| 19 | + |
| 20 | +<ul> |
| 21 | + <li><em>The middle element, if the elements of the sample were sorted and the number of elements is odd;</em></li> |
| 22 | + <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> |
| 23 | +</ul> |
| 24 | + |
| 25 | +<p> </p> |
| 26 | +<p><strong>Example 1:</strong></p> |
| 27 | +<pre><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] |
| 28 | +<strong>Output:</strong> [1.00000,3.00000,2.37500,2.50000,3.00000] |
| 29 | +</pre><p><strong>Example 2:</strong></p> |
| 30 | +<pre><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] |
| 31 | +<strong>Output:</strong> [1.00000,4.00000,2.18182,2.00000,1.00000] |
| 32 | +</pre> |
| 33 | +<p> </p> |
| 34 | +<p><strong>Constraints:</strong></p> |
| 35 | + |
| 36 | +<ol> |
| 37 | + <li><code>count.length == 256</code></li> |
| 38 | + <li><code>1 <= sum(count) <= 10^9</code></li> |
| 39 | + <li>The mode of the sample that count represents is unique.</li> |
| 40 | + <li>Answers within <code>10^-5</code> of the true value will be accepted as correct.</li> |
| 41 | +</ol> |
| 42 | + |
| 43 | +### Related Topics |
| 44 | + [[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] |
| 45 | + [[Two Pointers](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)] |
| 46 | + |
| 47 | +### Hints |
| 48 | +<details> |
| 49 | +<summary>Hint 1</summary> |
| 50 | +The hard part is the median. Write a helper function which finds the k-th element from the sample. |
| 51 | +</details> |
0 commit comments