Given a fixed-length integer array arr, duplicate each occurrence of zero, shifting the remaining elements to the right.

Note that elements beyond the length of the original array are not written. Do the above modifications to the input array in place and do not return anything.

&nbsp;
Example 1:

Input: arr = [1,0,2,3,0,4,5,0]
Output: [1,0,0,2,3,0,0,4]
Explanation: After calling your function, the input array is modified to: [1,0,0,2,3,0,0,4]


Example 2:

Input: arr = [1,2,3]
Output: [1,2,3]
Explanation: After calling your function, the input array is modified to: [1,2,3]


&nbsp;
Constraints:


	1 &lt;= arr.length &lt;= 104
	0 &lt;= arr[i] &lt;= 9


class Solution:
    def duplicateZeros(self, arr: List[int]) -> None:
        """
        Do not return anything, modify arr in-place instead.
        """
        l = len(arr)
        i,c=0,0
        while i<l:
            if arr[i]==0:
                arr.insert(i+1,0)
                i+=1
                arr.pop()
            i+=1
class Solution {
    
    //  Time Complexity = O(n)
    //  Space Complexity = O(1)
    
    public void duplicateZeros(int[] arr) {
        
        //  Loop through the array
        for(int i = 0; i < arr.length; i++) {
        
        //  Trigger Condition     
            if(arr[i] ==0) {
                int j;      // auxilliary variable for swapping 
                for(j = arr.length-2; j>=i+1; j--) {
                    arr[j+1] = arr[j];      //  Shift each element by one space
                }
                arr[j+1] = 0;               //  Duplicating the zero on the consecutive index of i
                i++;                        //  Skipping the duplicated zero index in the array 
            }
        }
    }       
}
class Solution {
public:
    void duplicateZeros(vector<int>& arr) {
        for(int i=0;i<arr.size();i++)
        {
          if(arr[i]==0)
          {
              arr.pop_back();
              arr.insert(arr.begin()+i,0);
              i++;
          }
            }

    }
};
/**
 * @param {number[]} arr
 * @return {void} Do not return anything, modify arr in-place instead.
 */
var duplicateZeros = function(arr) {
    // Variables
    const originalLength = arr.length;
    
    // Iterate over all the numbers in 'arr', if the number is 0 we duplicate it and skip the next loop iteration to prevent an overflow.
    for (let idx = 0; idx < arr.length; idx ++)
    {
      const number = arr[idx];
      if (number === 0 )
      {
        arr.splice(idx, 0, 0);
        idx += 1;
      };
    };
    
    // Here we restore the array to its original length.
    return (arr.length = originalLength);
};
Duplicate Zeros