Skip to content

Latest commit

 

History

History

Convert Array into Zig-Zag Fashion

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Given an array of DISTINCT elements, rearrange the elements of array in zig-zag fashion in O(n) time. The converted array should be in form a < b > c < d > e < f.

Input:  arr[] = {4, 3, 7, 8, 6, 2, 1}
Output: arr[] = {3, 7, 4, 8, 2, 6, 1}

Input:  arr[] =  {1, 4, 3, 2}
Output: arr[] =  {1, 4, 2, 3}