<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p>

<p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p>

<p>Return <em>the <strong>maximum possible frequency</strong> of an element after performing <strong>at most</strong> </em><code>k</code><em> operations</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,2,4], k = 5
<strong>Output:</strong> 3<strong>
Explanation:</strong> Increment the first element three times and the second element two times to make nums = [4,4,4].
4 has a frequency of 3.</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,4,8,13], k = 5
<strong>Output:</strong> 2
<strong>Explanation:</strong> There are multiple optimal solutions:
- Increment the first element three times to make nums = [4,4,8,13]. 4 has a frequency of 2.
- Increment the second element four times to make nums = [1,8,8,13]. 8 has a frequency of 2.
- Increment the third element five times to make nums = [1,4,13,13]. 13 has a frequency of 2.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> nums = [3,9,6], k = 2
<strong>Output:</strong> 1
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= k &lt;= 10<sup>5</sup></code></li>
</ul>

class Solution:
    def maxFrequency(self, nums: List[int], k: int) -> int:
        nums.sort()
        l = 0
        total = 0
        res = 0
        for r in range(len(nums)):
            total+=nums[r]
            if total + k <nums[r]*(r-l+1):
                total-=nums[l]
                l+=1
            res = max(r-l+1,res)
        return res















        nums.sort()
        l=0
        res = 0
        total = 0
        for r in range(len(nums)):
            total+=nums[r]
            if total+k<nums[r]*(r-l+1):
                total-=nums[l]
                l+=1
            res = max(res,r-l+1)
        return res



















        
        l,res = 0,0
        total = 0
        nums.sort()
        for  r in range(len(nums)):
            total+=nums[r]
            while total + k<nums[r]*(r-l+1):
                total -=nums[l]
                l+=1
            res = max(res,r-l+1)
        return res

















        l,ans = 0,0
        total = 0
        nums.sort()
        for  r in range(len(nums)):
            total += nums[r]
            while total + k<nums[r]*(r-l+1):
                total-=nums[l]
                l+=1
            ans = max(ans,r-l+1)
        return ans
        






















        nums.sort()
        l=0
        res = 0
        total = 0
        for r in range(len(nums)):
            total+=nums[r]
            while total + k<nums[r]*(r-l+1):
                total-=nums[l]
                l+=1
            res = max(r-l+1,res)
        return res
            



















        nums.sort()
        l=0
        res = 0
        total = 0
        for r in range(len(nums)):
            total+=nums[r]
            while ((r-l+1) * nums[r])>total+k:
                total-=nums[l]
                l+=1

            res = max(r-l+1,res)
        return res
























        l = 0
        nums.sort()
        res = 0
        total = 0
        for r in range(len(nums)):
            total+=nums[r]
            while nums[r]*(r-l+1)>k+total:
                total-=nums[l]
                l+=1
            res = max(res,r-l+1)
        return res































        nums.sort()
        l =0
        res = 0
        total = 0
        for r in range(len(nums)):
            total +=nums[r]
            while nums[r]*(r-l+1)>total+k:
                total-=nums[l]
                l+=1
            res = max(res,r-l+1)
        return res


































        nums.sort()
        l = 0
        total = 0
        res = 0
        for r in range(len(nums)):
            total += nums[r]
            while (r-l+1)*nums[r]> total+k:
                total-=nums[l]
                l+=1
            res = max(res,r-l+1)
        return res
            

        


































        nums.sort()
        l,r = 0,0
        total = 0
        maxl = 0
        while r<len(nums):
            total+=nums[r]
            if total + k <(r-l+1)*nums[r]:
                total-=nums[l]
                l+=1
                
            maxl = max(maxl,r-l+1)
            r+=1
            
        return maxl






































        nums.sort()
        r,l =0,0
        total = 0
        res = 0
        while r<len(nums):
            total+=nums[r]
            if nums[r]*(r-l+1)>total+k:
                total-=nums[l]
                l+=1
            res=max(res,r-l+1)
            r+=1
        return res




























        nums.sort()
        l,r = 0,0
        res= 0
        total = 0
        while r<len(nums):
            total +=nums[r]
            if nums[r]*(r-l+1)>total+k:
                total-=nums[l]
                l+=1
            res=max(res,r-l+1)
            r+=1
        return res

        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        nums.sort()
        l,r = 0,0
        res = 0
        total = 0
        while r<len(nums):
            total +=nums[r]
            if nums[r]*(r-l+1)>total+k:
                total -=nums[l]
                l+=1
            res = max(res,r-l+1)
            r+=1
        return res

        
30800