|
1 | 1 | # [1093.Statistics from a Large Sample][title]
|
2 | 2 |
|
3 |
| -> [!WARNING|style:flat] |
4 |
| -> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm) |
5 |
| -
|
6 | 3 | ## Description
|
| 4 | +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` where `count[k]` is the **number of times** that `k` appears in the sample. |
| 5 | + |
| 6 | +Calculate the following statistics: |
| 7 | + |
| 8 | +- `minimum`: The minimum element in the sample. |
| 9 | +- `maximum`: The maximum element in the sample. |
| 10 | +- `mean`: The average of the sample, calculated as the total sum of all elements divided by the total number of elements. |
| 11 | +- `median`: |
| 12 | + |
| 13 | + - If the sample has an odd number of elements, then the `median` is the middle element once the sample is sorted. |
| 14 | + - 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. |
| 15 | + |
| 16 | +- `mode`: The number that appears the most in the sample. It is guaranteed to be **unique**. |
| 17 | + |
| 18 | +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. |
7 | 19 |
|
8 | 20 | **Example 1:**
|
9 | 21 |
|
10 | 22 | ```
|
11 |
| -Input: a = "11", b = "1" |
12 |
| -Output: "100" |
| 23 | +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] |
| 24 | +Output: [1.00000,3.00000,2.37500,2.50000,3.00000] |
| 25 | +Explanation: The sample represented by count is [1,2,2,2,3,3,3,3]. |
| 26 | +The minimum and maximum are 1 and 3 respectively. |
| 27 | +The mean is (1+2+2+2+3+3+3+3) / 8 = 19 / 8 = 2.375. |
| 28 | +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. |
| 29 | +The mode is 3 as it appears the most in the sample. |
13 | 30 | ```
|
14 | 31 |
|
15 |
| -## 题意 |
16 |
| -> ... |
17 |
| -
|
18 |
| -## 题解 |
| 32 | +**Example 3:** |
19 | 33 |
|
20 |
| -### 思路1 |
21 |
| -> ... |
22 |
| -Statistics from a Large Sample |
23 |
| -```go |
24 | 34 | ```
|
25 |
| - |
| 35 | +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] |
| 36 | +Output: [1.00000,4.00000,2.18182,2.00000,1.00000] |
| 37 | +Explanation: The sample represented by count is [1,1,1,1,2,2,2,3,3,4,4]. |
| 38 | +The minimum and maximum are 1 and 4 respectively. |
| 39 | +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). |
| 40 | +Since the size of the sample is odd, the median is the middle element 2. |
| 41 | +The mode is 1 as it appears the most in the sample. |
| 42 | +``` |
26 | 43 |
|
27 | 44 | ## 结语
|
28 | 45 |
|
|
0 commit comments