FastPrepDuplicate Zeros
Problems/Duplicate Zeros

Duplicate Zeros

Microsoft logoMicrosoft● EasyNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A report from a Microsoft Data & Applied Scientist PhD internship names the Duplicate Zeros problem. The function returns the changed array. We chose the function signature and the limits.

Given a fixed-length integer array arr, duplicate each occurrence of 0. Shift the remaining values to the right and discard any values that move beyond the original array length.

Modify the array in place. Return the same array after you have changed it.

Function

duplicateZeros(arr: int[]) → int[]

Examples

Example 1

arr = [1,0,2,3,0,4,5,0]return = [1,0,0,2,3,0,0,4]

Each zero is copied once. Values shifted beyond the eighth position are discarded.

Example 2

arr = [1,2,3]return = [1,2,3]

There are no zeros to duplicate, so the array is unchanged.

Constraints

  • 1 <= arr.length <= 100000
  • 0 <= arr[i] <= 10^9

More Microsoft Onsite Interview questions

  • Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Sparse Vector Dot Product from TuplesMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Merge Sorted ArrayDP World · ONSITE INTERVIEW
  • Remove Duplicates From Sorted Array In PlaceKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Maximize Distance to the Closest Occupied SeatAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Merge Two Arrays Into Sorted OrderNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
  • Alternate Positive and Negative ValuesTesla · ONSITE INTERVIEWTesla interview questions
  • Make a Sorted Array Unique In PlaceAlpaca · ONSITE INTERVIEW
  • Maximize Distance to Closest Person — Return the SeatRoblox · ONSITE INTERVIEWRoblox interview questions
  • Move ZeroesBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Rotate an Array to the RightScale AI · ONSITE INTERVIEWScale AI interview questions

Interview reports that mention this question

  • Microsoft AI/ML Intern Interviews: 114 Experiences (Part 1 of 2)

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int[] duplicateZeros(int[] arr) {
      // Write your code here.
    }

}
Checking account…