Reduce Array Size to The Half
Remove at least half the numbers using as few distinct values as possible, by removing the most frequent values first.
01The problem
Choose a set of values and remove every occurrence of them from arr. Return the smallest number of values you need so that at least half the array is removed.
| Input | Output | Why |
|---|---|---|
[3,3,3,3,5,5,5,2,2,7] | 2 | remove 3 and 5: 7 of 10 gone |
[7, 7, 7, 7] | 1 | remove 7 |
Loading the rest of the lesson…