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.
- Zig Zag Sequence
- Discussions
Zig Zag Sequence
Zig Zag Sequence
Sort by
recency
|
132 Discussions
|
Please Login in order to post a comment
in C++
make three changes in the given code, to get sample test cases pass. modify your code to get debug exaclty...
void findZigZagSequence(vector < int > a, int n){ sort(a.begin(), a.end()); int mid = (n + 1)/2-1; //1st change swap(a[mid], a[n-1]);
}
In Python, I'm getting the same as the expected output but the tests fail.
`def findZigZagSequence(a, n): a.sort() mid = (n - 1)//2 a[mid], a[n-1] = a[n-1], a[mid]
There is no code provided in JavaScript
There doesn't seem to be a way to do this in typescript as @types/node is not included (is there a way to import modules with the hackerrank platform?). This error will appear when you try to run. solution.ts(3,1): error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try
npm i @types/node
.JAVA:
public static void findZigZagSequence(int [] a, int n){ Arrays.sort(a); int mid = n/2; int temp = a[mid]; a[mid] = a[n - 1]; a[n - 1] = temp;