5
int maxFrequency(vector<int> &nums, int k) {6
// sorting so that can easily find the optimal window7
sort(nums.begin(), nums.end());9
// left - left pointer of window10
// right - right pointer of window11
int left = 0, right = 0, ans = 1;12
ll total = 0, n = nums.size();14
// total - total sum of elements in the window17
// Checking if the we can achieve elements in this window18
// If it exceeds k then shrinking the window by moving left pointer19
// For optimal we will make all elements in the array equal to20
// the maximum value element21
while ((1ll) * (right - left + 1) * nums[right] - total > k) {26
ans = max(ans, right - left + 1);