java.lang.Object
g1301_1400.s1338_reduce_array_size_to_the_half.Solution

public class Solution extends Object
1338 - Reduce Array Size to The Half.<p>Medium</p> <p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> arr = [3,3,3,3,5,5,5,2,2,7]</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> Choosing {3,7} will make the new array [5,5,5,2,2] which has size 5 (i.e equal to half of the size of the old array).</p> <p>Possible sets of size 2 are {3,5},{3,2},{5,2}.</p> <p>Choosing set {2,7} is not possible as it will make the new array [3,3,3,3,5,5,5] which has a size greater than half of the size of the old array.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> arr = [7,7,7,7,7,7]</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> The only possible set you can choose is {7}. This will make the new array empty.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>2 <= arr.length <= 10<sup>5</sup></code></li> <li><code>arr.length</code> is even.</li> <li><code>1 <= arr[i] <= 10<sup>5</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minSetSize

      public int minSetSize(int[] arr)