Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

5. Move Zeroes

EasyDay 2 of 60Arrays & Hashing

Given an integer array nums, move every 0 to the end while keeping the relative order of the non-zero elements. Do it in place, without making a copy of the array. The function returns nothing.

Example 1
Input: nums = [0,1,0,3,12]
Output: [1,3,12,0,0]
The non-zero values 1, 3, 12 keep their order and the two zeros move to the back.
Example 2
Input: nums = [0]
Output: [0]
Constraints
  • 1 <= nums.length <= 10^4
  • -2^31 <= nums[i] <= 2^31 - 1
Hints
Frequently asked at: Meta, Amazon, Microsoft, Zoho, Wipro
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min