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?
Okay sure, im following below steps…
for eg… i/p is 1 4 2 3
sort it in ascending order to get 1 2 3 4
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.
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.
in the end after the bell sort is done I simply check the flag and print YES and the result_array or NO
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
try:
for i in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = set(a)
b = list(b)
if a == b:
print("YES")
print(*a)
else:
e = []
c = {}
for i in range(n):
if a[i] in c:
c[a[i]] += 1
e.append(a[i])
else:
c[a[i]] = 1
#print(c)
e.sort(reverse = True)
#print(e)
d = 0
c = sorted(c.items(), key=operator.itemgetter(0))
#c = dict(c)
#print(c)
if c[-1][1] > 1:
print("NO")
else:
c = dict(c)
for i in c:
if c[i] > 2:
d += 1
if d > 0:
print("NO")
else:
print("YES")
b = b + e
print(*b)
except EOFError:
pass