-
Notifications
You must be signed in to change notification settings - Fork 0
/
zig-zag-sequence.cpp
64 lines (58 loc) · 1.12 KB
/
zig-zag-sequence.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* @file zig-zag-sequence.cpp
* @author Alexander Khvolis(ExpliuM)
* @link https://www.hackerrank.com/challenges/zig-zag-sequence/problem?isFullScreen=true
* @version 0.1
* @date 2023-02-18
*
* @copyright Copyright (c) 2023
*
*
*/
#include <functional>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <limits>
// #include <bits/stdc++.h>
using namespace std;
void findZigZagSequence(vector<int> a, int n)
{
sort(a.begin(), a.end());
int mid = (n) / 2;
swap(a[mid], a[n - 1]);
int st = mid + 1;
int ed = n - 2;
while(st <= ed)
{
swap(a[st], a[ed]);
st = st + 1;
ed = ed - 1;
}
for (int i = 0; i < n; i++)
{
if (i > 0)
cout << " ";
cout << a[i];
}
cout << endl;
}
int main()
{
int n, x;
int test_cases;
cin >> test_cases;
for (int cs = 1; cs <= test_cases; cs++)
{
cin >> n;
vector<int> a;
for (int i = 0; i < n; i++)
{
cin >> x;
a.push_back(x);
}
findZigZagSequence(a, n);
}
}