|
| 1 | +<h2><a href="https://leetcode.com/problems/count-elements-with-at-least-k-greater-values">Count Elements With at Least K Greater Values</a></h2> <img src='https://img.shields.io/badge/Difficulty-Medium-orange' alt='Difficulty: Medium' /><hr><p>You are given an integer array <code>nums</code> of length <code>n</code> and an integer <code>k</code>.</p> |
| 2 | + |
| 3 | +<p>An element in <code>nums</code> is said to be <strong>qualified</strong> if there exist <strong>at least</strong> <code>k</code> elements in the array that are <strong>strictly greater</strong> than it.</p> |
| 4 | + |
| 5 | +<p>Return an integer denoting the total number of qualified elements in <code>nums</code>.</p> |
| 6 | + |
| 7 | +<p> </p> |
| 8 | +<p><strong class="example">Example 1:</strong></p> |
| 9 | + |
| 10 | +<div class="example-block"> |
| 11 | +<p><strong>Input:</strong> <span class="example-io">nums = [3,1,2], k = 1</span></p> |
| 12 | + |
| 13 | +<p><strong>Output:</strong> <span class="example-io">2</span></p> |
| 14 | + |
| 15 | +<p><strong>Explanation:</strong></p> |
| 16 | + |
| 17 | +<p>The elements 1 and 2 each have at least <code>k = 1</code> element greater than themselves.<br /> |
| 18 | +No element is greater than 3. Therefore, the answer is 2.</p> |
| 19 | +</div> |
| 20 | + |
| 21 | +<p><strong class="example">Example 2:</strong></p> |
| 22 | + |
| 23 | +<div class="example-block"> |
| 24 | +<p><strong>Input:</strong> <span class="example-io">nums = [5,5,5], k = 2</span></p> |
| 25 | + |
| 26 | +<p><strong>Output:</strong> <span class="example-io">0</span></p> |
| 27 | + |
| 28 | +<p><strong>Explanation:</strong></p> |
| 29 | + |
| 30 | +<p>Since all elements are equal to 5, no element is greater than the other. Therefore, the answer is 0.</p> |
| 31 | +</div> |
| 32 | + |
| 33 | +<p> </p> |
| 34 | +<p><strong>Constraints:</strong></p> |
| 35 | + |
| 36 | +<ul> |
| 37 | + <li><code>1 <= n == nums.length <= 10<sup>5</sup></code></li> |
| 38 | + <li><code>1 <= nums[i] <= 10<sup>9</sup></code></li> |
| 39 | + <li><code>0 <= k < n</code></li> |
| 40 | +</ul> |
0 commit comments