2465. Number of Distinct Averages Easy

@problem@discussion
#Array#Hash Table#Two Pointers#Sorting



1/**
2 * [2465] Number of Distinct Averages
3 *
4 * You are given a 0-indexed integer array nums of even length.
5 * As long as nums is not empty, you must repetitively:
6 * 
7 * 	Find the minimum number in nums and remove it.
8 * 	Find the maximum number in nums and remove it.
9 * 	Calculate the average of the two removed numbers.
10 * 
11 * The average of two numbers a and b is (a + b) / 2.
12 * 
13 * 	For example, the average of 2 and 3 is (2 + 3) / 2 = 2.5.
14 * 
15 * Return the number of distinct averages calculated using the above process.
16 * Note that when there is a tie for a minimum or maximum number, any can be removed.
17 *  
18 * <strong class="example">Example 1:
19 * 
20 * Input: nums = [4,1,4,0,3,5]
21 * Output: 2
22 * Explanation:
23 * 1. Remove 0 and 5, and the average is (0 + 5) / 2 = 2.5. Now, nums = [4,1,4,3].
24 * 2. Remove 1 and 4. The average is (1 + 4) / 2 = 2.5, and nums = [4,3].
25 * 3. Remove 3 and 4, and the average is (3 + 4) / 2 = 3.5.
26 * Since there are 2 distinct numbers among 2.5, 2.5, and 3.5, we return 2.
27 * 
28 * <strong class="example">Example 2:
29 * 
30 * Input: nums = [1,100]
31 * Output: 1
32 * Explanation:
33 * There is only one average to be calculated after removing 1 and 100, so we return 1.
34 * 
35 *  
36 * Constraints:
37 * 
38 * 	2 <= nums.length <= 100
39 * 	nums.length is even.
40 * 	0 <= nums[i] <= 100
41 * 
42 */
43pub struct Solution {}
44
45// problem: https://leetcode.com/problems/number-of-distinct-averages/
46// discuss: https://leetcode.com/problems/number-of-distinct-averages/discuss/?currentPage=1&orderBy=most_votes&query=
47
48// submission codes start here
49
50impl Solution {
51    pub fn distinct_averages(nums: Vec<i32>) -> i32 {
52        0
53    }
54}
55
56// submission codes end
57
58#[cfg(test)]
59mod tests {
60    use super::*;
61
62    #[test]
63    fn test_2465() {
64    }
65}
66


Back
© 2025 bowen.ge All Rights Reserved.