Got WA despite following all conditions? (INCRDEC)

Please have a look at my code and tell what went wrong.

All i did was:
sort the given array, start copying to another array from i=0 while iterating i=i+2 at each step, and putting every ith element at the first and i+1th element at the back of the array

This would result in the max possible value of p, and also put a check that any time two sequential elements were same it would return a NO, since the elements had to be strictly +ve or -ve?

Now do the same with this test case
1 2 3 4 2

I got o/p as
1 2 4 3 2

Is that not right, if not could you please elaborate as to how?

1 2 4 3 2 is correct

Shouldn’t it be 1 2 3 4 2 ?

both are correct
1 2 4 3 2 is increasing till 4 then it is decreasing

1 Like

hello i am new to codechef but can anyone tell when can we expect the editorial for this contest .

May I know why I got WA then? Is it possible that it could have been a memory issue?

(Tags: @admin3)

i think today itself (not sure)

can u explain ur code because it’s hard to understand :frowning:

Okay sure, im following below steps…
for eg… i/p is 1 4 2 3

  1. sort it in ascending order to get 1 2 3 4
  2. copy one by one… a[i] -> result_array[i] and a[i+1]-> result_array[last_index]
    this will give us a bell sort of our sorted array.
  3. Now to satisfy the other conditions (strictly increasing/decreasing) I placed a check every time i copy the elements that sees if the copied element matches its neighbors, if it does, it simply means o/p will be NO, a flag is set to 1, and I break out. or else i continue.
  4. in the end after the bell sort is done I simply check the flag and print YES and the result_array or NO

in eg case output will be

1 3 4 2

I did this, please tell me where I did wrong

You forgot to attach the link to your solution

Now is it working

No you are not attaching it properly , you should share your submission page link of that question.
The link you attached is redirecting to submit a solution for that problem not your code.

import operator
    for i in range(int(input())):
        n = int(input())
        a = list(map(int, input().split()))
        b = set(a)
        b = list(b)
        if a == b:
            e = []
            c = {}
            for i in range(n):
                if a[i] in c:
                    c[a[i]] += 1
                    c[a[i]] = 1
            e.sort(reverse = True)
            d = 0
            c = sorted(c.items(), key=operator.itemgetter(0))
            #c = dict(c)
            if c[-1][1] > 1:
                c = dict(c)
                for i in c:
                    if c[i] > 2:
                        d += 1
                if d > 0:
                    b = b + e
except EOFError:

I don’t know, how to attach solution.

what did i do wrong with my solution.

check your output

maybe youre not considering the case when the elements are similar at pos when the peak lies …
2 2 3 3
ans -> NO