We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 1b9100e + 89b6d34 commit 9d5c1a6Copy full SHA for 9d5c1a6
Hackerrank/Problem Solving/ZigZagSequence.cpp
@@ -0,0 +1,40 @@
1
+#include <bits/stdc++.h>
2
+using namespace std;
3
+
4
+void findZigZagSequence(vector < int > a, int n){
5
+ sort(a.begin(), a.end());
6
+ int mid = (n + 1)/2;
7
+ swap(a[mid], a[n-1]);
8
9
+ int st = mid + 1;
10
+ int ed = n - 1;
11
+ while(st <= ed){
12
+ swap(a[st], a[ed]);
13
+ st = st + 1;
14
+ ed = ed + 1;
15
+ }
16
+ for(int i = 0; i < n; i++){
17
+ if(i > 0) cout << " ";
18
+ cout << a[i];
19
20
+ cout << endl;
21
+}
22
23
+int main() {
24
+ int n, x;
25
+ int test_cases;
26
+ cin >> test_cases;
27
28
+ for(int cs = 1; cs <= test_cases; cs++){
29
+ cin >> n;
30
+ vector < int > a;
31
32
+ cin >> x;
33
+ a.push_back(x);
34
35
+ findZigZagSequence(a, n);
36
37
38
39
40
0 commit comments