Given an unsorted array, I am trying to find the K nearest elements to the median of an Array. I am having trouble finding the solution in linear running time.
A[] = 1, 2, 3, 4, 5 ,6 , 30 ,31, 32 ,33 ,34 # assume sorting part is done
Median here is 6.
Answer for this is 2,3,4,5,6.
Any help or hint will be appreciated.
assume sorting part is done
? If it should run in linear time, how can we assume that? Is it allowed to use additional data structures? - Duarte Meneses