Impostor_Syndrome's blog

By Impostor_Syndrome, history, 3 years ago, In English

In an array — 'arr' there are n elements. Two elements arr[i] and arr[j] can be combined to one element if arr[i] >= k * arr[j], for i != j. After combination, these two elements cannot further combine with any other element of the array. Find the minimum size of the array possible, after executing atmost n/2 operations.

Input will be n, the array elements and k.

»
3 years ago, # |
  Vote: I like it +10 Vote: I do not like it

Please share source/link to the problem statement.

»
3 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

When the order of the elements does not matter (as in the problem you described), it is generally a good idea to sort the array and assume the elements in order when coming up with a solution.
This said, each match decreases the size of the array by one, therefore the final size will be $$$n - matches$$$. If the final size has to be minimal, you want to maximize the numbers of matches.

One possible way of doing it: