ANUUND - Editorial

CodeChef: Practical coding for everyone . Plz tell me what is wrong with this soon. Thnx in advance

@invest123 You must take into account the separate test cases. you are printing for only one test case!

Thnx. OMG what a mistake :slight_smile: Dint notice that. I think i should use ideone to avoid these mistakes.

what is condition to test cases

He did not pass with this solution. I have updated the new solution.

Your solution is correct, but you are answering for a single test case only. You are not even reading number of test cases.

1 Like

I am not sure what the error was but the error was probably in map(int,s.split(" ")) , when I replaced it with [int(x) for x in s.split()] it worked .
Here is your corrected code .
http://www.codechef.com/viewsolution/3925500

1 Like

You are declaring the array in while (testcase --) loop, which is not correct. Number of test cases could be very huge, If you keep allocating so much memory for so many loops, you will get TLE. Ideally you should use vector or you should declare the array globally.

your sorting step is O(N 2 ). You need faster algorithms for sorting. Eg quicksort, mergesort etc. Btw you can use simply STL function sort.

PLEASE CORRECT THE EDITORIAL TO
A[i] >= A[i + 1] if i is odd.
A[i] <= A[i + 1] if i is even.

Hello guys! I’m new to the platform.
How do I read the input using Pythong.
Thanks!

For a single integer you could use:

T = int(input())

And to get a set of whitespace-separated items into a list

items = input().split()

or if you want them as a list of integers:

values = list( map(int, input().split()) )
1 Like

This is my solution, similar to approach 1, but slightly different. I am not sure why or where it is going wrong…

for i in range((int(input()))):
m = int(input())
n = list(map(int, input().split()))
n.sort()
if m >= 3:
for j in range(1, m-2, 2):
n[j], n[j+1] = n[j+1], n[j]
print(n)