Practice Duplicate Zeros
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
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.
Source: Duplicate Zeros on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
arr = [1,0,2,3,0,4,5,0]
Output
[1,0,0,2,3,0,0,4]
# Example 2
Input
arr = [1,2,3]
Output
[1,2,3]
Constraints
1 <= arr.length <= 10^4
0 <= arr[i] <= 9
Related LeetCode Problems
Practice more problems similar to Duplicate Zeros.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.