Please subscribe to the official Codeforces channel in Telegram via the link: https://t.me/codeforces_official. ×

### purist's blog

By purist, history, 5 months ago, ,

Given an array, we can generate an array which stores all the pairwise absolute difference of elements of original array. How can we find median of this new array. For example : A = {1,2,3,4} then we can generate difference array as G = {1,1,1,2,2,3} then median is 1.can it be done in better than quadratic time? Also what if we don't take absolute value of difference?

•
• +16
•

 » 5 months ago, # |   +16 N *logN logN approach. - 1. Sort the elements. - 2. Do binary search on median. - 3. For a particular value of median you can check how many pairwise elements will be smaller than the median. You can do this N log N , as you will have do again binary search on array.
•  » » 5 months ago, # ^ |   +11 Actually it can be done in by using two pointers technique.
•  » » » 5 months ago, # ^ |   0 Can you explain your approach?
•  » » 5 months ago, # ^ |   0 How do you check number of pairs smaller than current value using binary search?