Skip to content

Files

Latest commit

41cddf7 · Jan 5, 2019

History

History

Array Rearrangement by Shifting Zero to end

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jan 5, 2019
Jan 5, 2019

Given an array of integers of size n. Assume ‘0’ as invalid number and all other as valid number. Convert the array in such a way that if next valid number is same as current number, double its value and replace the next number with 0. After the modification, rearrange the array such that all 0’s are shifted to the end.

Input : arr[] = {2, 2, 0, 4, 0, 8}
Output : 4 4 8 0 0 0

Input : arr[] = {0, 2, 2, 2, 0, 6, 6, 0, 0, 8}
Output :  4 2 12 8 0 0 0 0 0 0