FastPrepMinimum Removals to Balance Array
Problems/Minimum Removals to Balance Array

Minimum Removals to Balance Array

Salesforce logoSalesforce● MediumFULLTIMEOA

Updated Aug 2026

QuestionFunctionExamples

Problem statement

You are given an integer array arr.

The array is called balanced if:

  • the largest element is at most twice the smallest element

You may perform the following changes:

  • Remove any number of elements
  • Modify at most one remaining element to any positive integer

Your task is to determine the minimum number of elements that must be removed so that the resulting array can be made balanced under these rules.

Function

minimumRemovalsToBalance(arr: int[]) → int

Examples

Example 1

arr = [7, 4, 2, 3, 12, 9]return = 2

An optimal sequence of operations is:

  • Change the second element from 4 to 8.
  • Remove the third and fourth elements, 2 and 3.
    • The modified array is [7, 8, 12, 9]
    • 12 is less than or equal to 2 * 7.

Example 2

arr = [4, 6, 2, 9, 8, 7, 3]return = 2

An optimal sequence of operations is:

  • Change the third element from 2 to 11
  • Remove the first and seventh elements, 4 and 3.
    • The modified array is [6, 11, 9, 8, 7]
    • 11 is less than or equal to 2 * 6.

More Salesforce Online Assessment questions

  • Count Subarrays With Product Equal to KOA · Seen Nov 2026
  • Minimum No-Repeat Segments After One Character RemovalOA · Seen Nov 2026
  • Get Message StatusOA · Seen Nov 2026
  • Minimum Unique-Character Segments After DeletionOA · Seen Sep 2026
  • Run-Length String CompressionOA · Seen Sep 2026
  • Maximum Requests in WindowOA · Seen Sep 2026
  • Final Pod Counts After LogsOA · Seen Aug 2026
  • Is This Date a Weekend?OA · Seen Aug 2026
  • Maximum Barbell WeightOA · Seen Jul 2026
  • Minimum Operations to ZeroOA · Seen Jul 2026

Similar questions at other companies

  • Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
  • Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
  • Minimum Machines for TasksExpedia · OAExpedia interview questions
  • Find Minimum Possible SizeMathWorks · OAMathWorks interview questions
  • Minimum Days to Watch All MoviesAdobe · OAAdobe interview questions
  • Efficient Janitor TripsRoblox · OARoblox interview questions
  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Can Every Package Fit in a BoxIMC Trading · OAIMC Trading interview questions
  • Minimum Tunnel Crossing TimeArcesium · OAArcesium interview questions
  • Get Maximum PairsAmazon · OA

Salesforce interview experiences

  • Salesforce Infrastructure SWE OA and Onsite: 1 Experience
  • Salesforce Experienced Backend SWE First Round: 1 Experience
All Salesforce interview questionsSee Salesforce hiring insights
Saved
class Solution {
    public int minimumRemovalsToBalance(int[] arr) {
      // write your code here
    }

}
Checking account…