We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Debugging
- Zig Zag Sequence
- Discussions
Zig Zag Sequence
Zig Zag Sequence
Sort by
recency
|
93 Discussions
|
Please Login in order to post a comment
Only change 3 lines but doesn't provide all languages. So if you make a new solution from scratch, your solution always fails due to creating more than 3 lines of code.
Python 3 (comments on changed lines)
i have made my solution in c and it's workig with the exact output when debuging on codeblocks but when submitting it on the site it gives me wrong answer
Although the expected output is matching with my output it's not passing. def findZigZagSequence(a, n): a.sort()#Sorting the array mid = int(n/2)#Finding the middle element a[mid], a[n-1] = a[n-1], a[mid] #Swapping the middle element with the max number #print(a) st = mid + 1 ed = n - 2 while(st <= ed): a[st], a[ed] = a[ed], a[st] st = st + 1 ed = ed - 1
test_cases = int(input()) for cs in range (test_cases): n = int(input()) a = list(map(int, input().split())) findZigZagSequence(a, n)
I am not sure how to make this 3 lines or less in JS and there is no
findZigZagSequence
function to debug, but here's my solution (which isn't passing despite the output matching what is expected 🤔) I feel like this is fairly sloppy though.