1338. Reduce Array Size to The Half Medium
1/**
2 * [1338] Reduce Array Size to The Half
3 *
4 * You are given an integer array arr. You can choose a set of integers and remove all the occurrences of these integers in the array.
5 * Return the minimum size of the set so that at least half of the integers of the array are removed.
6 *
7 * Example 1:
8 *
9 * Input: arr = [3,3,3,3,5,5,5,2,2,7]
10 * Output: 2
11 * Explanation: Choosing {3,7} will make the new array [5,5,5,2,2] which has size 5 (i.e equal to half of the size of the old array).
12 * Possible sets of size 2 are {3,5},{3,2},{5,2}.
13 * Choosing set {2,7} is not possible as it will make the new array [3,3,3,3,5,5,5] which has a size greater than half of the size of the old array.
14 *
15 * Example 2:
16 *
17 * Input: arr = [7,7,7,7,7,7]
18 * Output: 1
19 * Explanation: The only possible set you can choose is {7}. This will make the new array empty.
20 *
21 *
22 * Constraints:
23 *
24 * 2 <= arr.length <= 10^5
25 * arr.length is even.
26 * 1 <= arr[i] <= 10^5
27 *
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/reduce-array-size-to-the-half/
32// discuss: https://leetcode.com/problems/reduce-array-size-to-the-half/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37 pub fn min_set_size(arr: Vec<i32>) -> i32 {
38 0
39 }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn test_1338() {
50 }
51}
52
Back
© 2025 bowen.ge All Rights Reserved.