Skip to content
Decoder

Reduce Array Size to The Half

Medium

Problem

Pick a set of values and delete every occurrence of each picked value from arr. Return the minimum size of the set that removes at least half of the elements.

Example 1

Input
arr = [3, 3, 3, 3, 5, 5, 5, 2, 2, 7]
Output
2
Why
remove 3 and 5: 3 elements left

Example 2

Input
arr = [7, 7, 7, 7, 7, 7]
Output
1

Example 3

Input
arr = [1, 2, 3, 4]
Output
2

Constraints

  • 2 <= arr.length <= 10^5
  • arr.length is even.
  • 1 <= arr[i] <= 10^5

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.