3759. Count Elements With at Least K Greater Values Medium

@problem@discussion
#Array#Binary Search#Divide and Conquer#Sorting#Quickselect



1/**
2 * [3759] Count Elements With at Least K Greater Values
3 *
4 * You are given an integer array nums of length n and an integer k.
5 * An element in nums is said to be qualified if there exist at least k elements in the array that are strictly greater than it.
6 * Return an integer denoting the total number of qualified elements in nums.
7 *  
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">nums = [3,1,2], k = 1</span>
11 * Output: <span class="example-io">2</span>
12 * Explanation:
13 * The elements 1 and 2 each have at least k = 1 element greater than themselves.<br />
14 * ​​​​​​​No element is greater than 3. Therefore, the answer is 2.
15 * </div>
16 * <strong class="example">Example 2:
17 * <div class="example-block">
18 * Input: <span class="example-io">nums = [5,5,5], k = 2</span>
19 * Output: <span class="example-io">0</span>
20 * Explanation:
21 * Since all elements are equal to 5, no element is greater than the other. Therefore, the answer is 0.
22 * </div>
23 *  
24 * Constraints:
25 * 
26 * 	1 <= n == nums.length <= 10^5
27 * 	1 <= nums[i] <= 10^9
28 * 	0 <= k < n
29 * 
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/count-elements-with-at-least-k-greater-values/
34// discuss: https://leetcode.com/problems/count-elements-with-at-least-k-greater-values/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39    pub fn count_elements(nums: Vec<i32>, k: i32) -> i32 {
40        0
41    }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn test_3759() {
52    }
53}
54

Back
© 2026 bowen.ge All Rights Reserved.