QUESTION FROM AN ASSESSMENT

Given an integer list an element can be removed if there exists another element in the list that is atleast twice as big as the current element.
ie.for each such merge the array size will be reduced by 1.
return the size of the smallest list possible by applying the above operation.
Note- 1.the list is not sorted.
2.each element can only be used ones.
3.the array is not empty.

example-input-[1,2,4,4,4,5,8,9] size-8
output-[4,5,8,9] size- 4
explaination-two 4s can go in 8 and 9. ie size=size-2=6; [1,2,4,5,8,9](8 and 9 are already used)
2 can go in 5 ie size=size-1=5 [1,4,5,8,9](5 is used in this step)
1 can go in 4 ie size=size-1=4 [4,5,8,9](4 is used in this step)

can anyone think of an algorithm that works in less then O(nlogn)?

Thanks

Comments (0)