You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: explanations/3759/en.md
-3Lines changed: 0 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,9 +29,6 @@ We sort the array first, which allows us to efficiently determine how many eleme
29
29
5. If the number of greater elements is at least `k`, add the count of current value to the result.
30
30
6. Move to the next distinct value and repeat.
31
31
32
-
***Brute Force:** For each element, count how many other elements are strictly greater by comparing with all other elements. This takes O(n^2) time.
33
-
***Optimized Strategy:** Sort the array first. Then for each distinct value, use binary search to find the first element strictly greater than it. The number of greater elements is `n - upper_bound_index`. This reduces the time complexity to O(n log n).
34
-
35
32
**2.1 Initialization & Example Setup:**
36
33
37
34
Let's use the example `nums = [3, 1, 2]`, `k = 1` to trace through the solution.
0 commit comments