AVGSORT - Editorial

Hi there, in the explanation it says for any case other than an array of decreasing order, its always possible to have a strictly decreasing array.

BUT what about this testcase arr = {7, 9, 10, 2, 5} here isn’t it impossible to have a strictly decreasing array ???

can you help me in this case ?

Your array is A=[7,9,10,2,5]. You find the pair A_1<A_2 then you make the right part of the array almost equal to A_2 i.e. 9.

Hence your array will look like A=[7,9,9.00001,8.999999,8.999999] something like this.

Now, as explained in the editorial our right part of the array will be like :

Right_Arr = [9-diff/4, 9.00001-diff/8, 8.999999-diff/16, 8.999999-diff/32], where

diff=A_2-A_1 i.e 2.

Finally merge the left and right part of the array. Your array is now in the form of strictly increasing order.

The problem asks to check whether the sequence can be made strictly increasing. In your comment you have written to make sequence to strictly decreasing, I have taken that as a typo.

Although your given sequence can be made to strictly decreasing too with the help of pair (10,2) by interchanging the process for the left and right part of array.

7 2 4 1 6 8 3 9

Choose 1

Lets look left :

so we have 7 2 4 1…

Now if we keep repeating the operation then after some finite number of times(howsoever huge) we can get 7 2 4 1.000…001 1…

similarly we can make the 2 to become 1.0000…000001 and so on.

Repeat the same for the right part uptil the last element.

So we have :
1+1e(-very big number),1+1e(-very big number),…1…,1+1e(-very big number),9

Which is nearly of the form [m m m m m… >m]

This can be treated to become strictly increasing. Turn the second last element into average of 9 and 1+1e(-very big number) and so on till the first element becomes the minimum.

Thank you. :smile:

ok got it. Thanks

yup i basically meant whether this case can be made a strictly increasing array or not. Thnx !!

Can you explain what is prefix min and suffix max? Any resource would be helpful.

@cj2021 Um lets see:
for 7 and 2, you can make 7 very close to 2, greater than 2 but not equal. lets say 2.00001 2 but the sequence is still not increasing, so you need to increase 2 by an infinitesimal amount to make it greater than 2. How you do that? By increasing it with the help of a larger number than it, here it is 4. So the order becomes something like: 2.00001 2.00002 4. You can keep on repeating this to get the full sorted sequence.

Nice catch