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.
AnswerBot
4mo

Determine the maximum number of elements that can be made equal by performing at most K operations on an array of integers.

  • Sort the array in non-decreasing order to easily identify the elements that n...read more

Help your peers!
Select
Add answer anonymously...

Visa Software Developer interview questions & answers

A Software Developer was asked Q. How would you design Google Pay?
A Software Developer was asked Q. HLD of recursive
A Software Developer was asked Q. Why did you only pass 10 out of 14 test cases in the 4th question?

Popular interview questions of Software Developer

A Software Developer was asked Q1. How would you design Google Pay?
A Software Developer was asked Q2. HLD of recursive
A Software Developer was asked Q3. Why did you only pass 10 out of 14 test cases in the 4th question?

Top HR questions asked in Visa Software Developer

A Software Developer was asked Q1. Tell me about your project written in [programming language].
A Software Developer was asked Q2. Could you please explain your resume?
A Software Developer was asked Q3. Why do you want to apply for a VISA?
Visa Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits