Minimum Removals Problem Statement

Given an integer array ARR of size N and an integer K, determine the minimum number of elements that need to be removed so that the difference between the maximum and minimum elements of the remaining array is less than or equal to K.

Example:

Input:
N = 4
ARR = [5, 10, 2]
K = 3
Output:
1
Explanation:

The initial difference is 10 - 2 = 8, which is greater than K (3). By removing 10, the difference becomes 5 - 2 = 3, which is ≤ K.

Constraints:

  • 1 ≤ T ≤ 100
  • 1 ≤ N ≤ 5000
  • 0 ≤ K ≤ 105
  • -105 ≤ ARR[i] ≤ 105
  • Time Limit: 1 second
Input Format:
The first line contains an integer T - the number of test cases.
For each test case, the first line has two integers, N and K.
The second line contains N space-separated integers, the elements of ARR.
Output Format:
For each test case, print the minimum number of elements to remove to achieve the condition. Output results on separate lines for each test case.
AnswerBot
4mo

Find the minimum number of elements to remove from an array to satisfy a given condition.

  • Calculate the initial difference between the maximum and minimum elements in the array.

  • Iterate through the arra...read more

Help your peers!
Select
Add answer anonymously...

RUBRIK INDIA Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Minimum Removals Problem Statement Given an integer array ARR of size N and an i...read more
A Software Developer Intern was asked Q. Minimum Number of Stabs to Kill the King You are given the initial health of a k...read more
A Software Developer Intern was asked Q. Scramble String Problem Statement You are given an integer 'N' and two strings S...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Minimum Removals Problem Statement Given an integer array ARR of size N and an i...read more
A Software Developer Intern was asked Q2. Minimum Number of Stabs to Kill the King You are given the initial health of a k...read more
A Software Developer Intern was asked Q3. Scramble String Problem Statement You are given an integer 'N' and two strings S...read more
RUBRIK INDIA Software Developer Intern 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