Input: N = 6, arr[] = [1, 2, 2, 1, 1, 0]
Output: [1, 4, 2, 0, 0, 0]
Explanation: At i = 0: arr[0] and arr[1] are not the same, so we do nothing.
At i = 1: arr[1] and arr[2] are the same, so we multiply arr[1] with 2 and change its next element to 0.
array = [1, 4, 0, 1, 1, 0]
At i = 2: arr[2] and arr[3] are not the same, so we do nothing.
At i = 3: arr[3] and arr[4] are the same, so we multiply arr[3] with 2 and change its next element to
arr[] = [1, 4, 0, 2, 0, 0]
At i = 4: arr[4] and arr[5] are the same, so we multiply arr[4] with 2 and change its next element to 0.
arr[] = [1, 4, 0, 2, 0, 0]
After applying the above 2 conditions, shift all the 0's to the right side of the array.
arr[]= [1, 4, 2, 0, 0, 0]
Input: N =2, arr[] = [0, 1]
Output: [1, 0]
Explanation: At i = 0: arr[0] and arr[1] are not same, so we do nothing.
No conditions can be applied further, so we shift all 0's to right.
arr[] = [1, 0]
Consider an array arr[] = {1, 2, 2, 1, 1, 0};
At i = 0:
arr[0] and arr[1] are not the same, so we do nothing.
At i = 1:
arr[1] and arr[2] are the same, so we multiply arr[1] with 2 and change its next element to 0.
arr[] = [1, 4, 0, 1, 1, 0]
At i = 2:
arr[2] and arr[3] are not the same, so we do nothing.
At i = 3:
arr[3] and arr[4] are the same, so we multiply arr[3] with 2 and change its next element to 0.
arr[]= [1, 4, 0, 2, 0, 0]
At i = 4:
arr[4] and arr[5] are the same, so we multiply arr[4] with 2 and change it's next element to 0.
arr[] = [1, 4, 0, 2, 0, 0]
After applying the above 2 conditions, shift all the 0's to right side of the array.
arr[] = [1, 4, 2, 0, 0, 0]
Below is the implementation of the above approach.