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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Interview Preparation Kits
  3. 1 Month Preparation Kit
  4. Week 2
  5. Zig Zag Sequence

Zig Zag Sequence

Problem
Submissions
Leaderboard
Discussions
Editorial
  1. Prepare
  2. Interview Preparation Kits
  3. 1 Month Preparation Kit
  4. Week 2
  5. Zig Zag Sequence
Exit Full Screen View
  • Problem
  • Submissions
  • Leaderboard
  • Discussions
  • Editorial

In this challenge, the task is to debug the existing code to successfully execute all provided test files.


Given an array of distinct integers, transform the array into a zig zag sequence by permuting the array elements. A sequence will be called a zig zag sequence if the first elements in the sequence are in increasing order and the last elements are in decreasing order, where . You need to find the lexicographically smallest zig zag sequence of the given array.

Example.

Now if we permute the array as , the result is a zig zag sequence.

Debug the given function findZigZagSequence to return the appropriate zig zag sequence for the given input array.

Note: You can modify at most three lines in the given code. You cannot add or remove lines of code.

To restore the original code, click on the icon to the right of the language selector.

Input Format

The first line contains the number of test cases. The first line of each test case contains an integer , denoting the number of array elements. The next line of the test case contains elements of array .

Constraints


( is always odd)

Output Format

For each test cases, print the elements of the transformed zig zag sequence in a single line.

  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy