Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Duplicate Zeros

XPChallenge Points: 10
levelLevel: Easy

You are given an integer array arr of a fixed size.
Each time a zero appears in the array, you must duplicate it and shift all elements to the right.

  • The array should not grow beyond its original length.

  • Any elements pushed out of bounds are removed.

  • The modification must be done in the same array (in-place).

Example 1:

Input: arr = [8,6,0,4]

Output: [8,6,0,0]

Explanation:

Zero at index 2 is copied and pushes out remaining elements.

Example 2:

Input: arr = [0,1,0,2]

Output: [0,0,1,0]

Explanation:

- First zero → duplicate → [0,0,1,0,2] but we keep only first 4 → [0,0,1,0]

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result