Move Zeroes in One Scan
Updated
Problem statement
Move every zero in nums to the end while preserving the original order of the positive entries. Mutate the array and return its resulting contents.
The final solution must inspect the input in one forward scan and use constant auxiliary space. Empty input returns an empty array.
Function
moveZeroes(nums: int[]) → int[]Examples
Example 1
nums = [0,1,0,3,12]return = [1,3,12,0,0]The nonzero values remain in their original order and both zeroes move to the suffix.
Example 2
nums = [0]return = [0]A one-zero array is unchanged.
Constraints
0 <= nums.length <= 10000.0 <= nums[i] <= 1000000000.
More Expedia Onsite Interview questions
- Scramble StringONSITE INTERVIEW · Seen Sep 2026
- Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
- Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
- Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
- Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
- Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
- Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
- Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
- Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
- Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024
Similar questions at other companies
- 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
- Sparse Vector Dot Product from TuplesMeta · ONSITE INTERVIEWMeta interview questions
- Make a Sorted Array Unique In PlaceAlpaca · ONSITE INTERVIEW
- Two SumMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Maximize Distance to Closest Person — Return the SeatRoblox · ONSITE INTERVIEWRoblox interview questions
- Move ZeroesBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
Interview reports that mention this question
Expedia interview experiences
- Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
- Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
- Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
- Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
- Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)