3

Convert array into Zig-Zag fashion | SDE Sheet | Arrays

 2 years ago
source link: https://www.geeksforgeeks.org/videos/convert-array-into-zig-zag-fashion/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Convert array into Zig-Zag fashion
Convert array into Zig-Zag fashion | SDE Sheet | Arrays
Video Player is loading.
Loaded: 0%
00:00
Remaining Time -11:18
  • 80 Views
  • 11/04/2022

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. Compare 2 elements at a time and accordingly place the larger element or the smaller element.

Example: Input: {4, 3, 7, 8, 6, 2, 1} Output: {3, 7, 4, 8, 2, 6, 1} As you can see 3 < 7 > 4 < 8 > 2 < 6 > 1

Check out the video to see how we implement this!!

Practice Problem: https://practice.geeksforgeeks.org/problems/convert-array-into-zig-zag-fashion1638/1 Article: https://www.geeksforgeeks.org/convert-array-into-zig-zag-fashion/ SDE Sheet: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK