Maximum Equal Elements After K Operations

You are provided with an array/list of integers named 'ARR' of size 'N' and an integer 'K'. Your task is to determine the maximum number of elements that can be made equal to each other by performing at most 'K' operations.

An operation is defined as increasing an element from 'ARR' by 1.

Input:

The first line contains a single integer T, the number of test cases.
For each test case:
The first line contains two space-separated integers, N (size of 'ARR') and K (maximum number of operations).
The second line contains N space-separated integers, the elements of 'ARR'.

Output:

For each test case, output a single integer denoting the maximum number of elements that can be made equal after using K or fewer operations.

Example:

Input:
1
5 3
1 2 4 6 8

Output:
3

Constraints:

  • 1 <= T <= 10^2
  • 1 <= N <= 10^3
  • 1 <= ARR[i], K <= 10^9

Note:

You can perform multiple operations on a single element. You only need to implement the function as printing is managed externally.
Be the first one to answer
Add answer anonymously...
Visa Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter