Java: Move all Zeros to the beginning of an array

Level : Beginner
Mentor: Shailendra Chauhan
Type : GuidedLab
Points : 10
Duration : 00:25:00

Lab Details

Difficulty Level: MEDIUM

Problem Statement:

Given an integer array, move all elements that are 0 to the left while maintaining the order of other elements in the array. The array has to be modified in place and remember to maintain the order of the non-zero elements.

Input:

Array = [1,0,2,5,0,7,9,0]

Output:

Array = [0,0,0,1,2,5,7,9]


Self-paced Membership
  • 24+ Video Courses
  • 825+ Hands-On Labs
  • 400+ Quick Notes
  • 125+ Skill Tests
  • 10+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this