medium 0 views
Minimum Removals to Balance Array
You are given an integer array nums and an integer k.
You are given an integer array nums and an integer k.
An array is considered balanced if the value of its maximum element is at most k times the minimum element.
You may remove any number of elements from nums without making it empty.
Return the minimum number of elements to remove so that the remaining array is balanced.
Note: An array of size 1 is considered balanced as its maximum and minimum are equal, and the condition always holds true.
Example 1
Input: nums = [2,1,5], k = 2
Output: 1
Example 2
Input: nums = [1,6,2,9], k = 3
Output: 2
Example 3
Input: nums = [4,6], k = 2
Output: 0
Constraints
- 1 <= nums.length <= 10^5
- 1 <= nums[i] <= 10^9
- 1 <= k <= 10^5
Hints
Companies
No companies reported yet.
Discussion
Sign in to join the discussion.
Loading discussion...
Test results
No test cases yet.