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.
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
int numTests = sc.nextInt();
for (int i=0; i < numTests; i++) {
int n = sc.nextInt();
int k = (n+1)/2;
List<Integer> list = new ArrayList<>();
List<Integer> result = new ArrayList<>();
for (int j=0; j < n; j++) {
list.add(sc.nextInt());
}
sc.close();
Collections.sort(list);
result.addAll(list.subList(0, k-1));
list.removeAll(list.subList(0, k-1));
Collections.reverse(list);
result.addAll(list);
for (Integer val : result) {
System.out.print(val + " ");
}
System.out.println();
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Zig Zag Sequence
You are viewing a single comment's thread. Return to all comments →