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.
Examples
01 · Example 1
arr = [7, 4, 2, 3, 12, 9] return = 2
An optimal sequence of operations is:
- Change the second element from
4to8. - Remove the third and fourth elements,
2and3.- The modified array is
[7, 8, 12, 9]. 12is less than or equal to2 * 7.
- The modified array is
02 · Example 2
arr = [4, 6, 2, 9, 8, 7, 3] return = 2
An optimal sequence of operations is:
- Change the third element from
2to11. - Remove the first and seventh elements,
4and3.- The modified array is
[6, 11, 9, 8, 7]. 11is less than or equal to2 * 6.
- The modified array is
More Salesforce problems
- Minimize Total Input Cost (for LTMS)Seen Jun 2026
- Count Prime StringsONSITE INTERVIEW · Seen Jun 2026
- Final Pod Counts After LogsOA · Seen May 2026
- Key Teams in TreeOA · Seen Mar 2026
- System Energy ReductionOA · Seen Mar 2026
- Update Logs by Symmetric XOROA · Seen Mar 2026
- Count Palindromic Concatenation PairsOA · Seen Mar 2026
- Collect Opportunity Data in a TreeOA · Seen Feb 2026
public int minimumRemovalsToBalance(int[] arr) {
// write your code here
}
arr[7, 4, 2, 3, 12, 9]
expected2
checking account