14. Frequency of the Most Frequent Element
The frequency of an element is the number of times it occurs in an array.
You are given an integer array nums
and an integer k
. In one operation, you can choose an index of nums
and increment the element at that index by 1
.
Return the maximum possible frequency of an element after performing at most k
operations.
Example 1:
Example 2:
Example 3:
Solution:(Greedy + Sliding Window)
Approach: Sorting the array Finding Sliding window condition: (arr[i] * (i-start) - sum)<=k
Time Complexity: O(n log n)
Previous13. Shortest Subarray with Sum at Least K (Negative Numbers)Next15. Count Number of Nice Subarrays
Last updated