O18
Move Zeroes to End
Problem Statement & Objective
Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements. You must do this in-place without making a copy of the array.
Function Signature (Python)
move_zeroes(nums: list[int]) -> list[int]Input & Output Contract
Output Rule:The array modified in-place with all zeroes shifted to the end.
System Constraints
1 <= nums.length <= 10^5
-2^31 <= nums[i] <= 2^31 - 1Example Execution Walkthrough
nums = [0, 1, 0, 3, 12]
result: [1, 3, 12, 0, 0]Example Test Scenarios (3)
Example 1
Input:
[[0,1,0,3,12]]Expected Output:
[1,3,12,0,0]Example 2: Tek Sıfır
Input:
[[0]]Expected Output:
[0]Example 3: Sıfırsız Dizi
Input:
[[1,2,3]]Expected Output:
[1,2,3]