FlareStart
HomeNewsHow ToSources
FlareStart

Where developers start their day. All the tech news & tutorials that matter, in one place.

Quick Links

  • Home
  • News
  • Tutorials
  • Sources
  • Privacy Policy

Connect

© 2026 FlareStart. All rights reserved.

Back to articles
CA 13 - Move Zeros
NewsTools

CA 13 - Move Zeros

via Dev.to TutorialSuruthika4h ago

Problem Move Zeroes You are given an integer array nums. Your task is to move all 0s to the end while maintaining the relative order of non-zero elements. The operation must be done in-place, without using extra space. Input: [0, 1, 0, 3, 12] → Output: [1, 3, 12, 0, 0] Input: [0] → Output: [0] Approach The idea is to shift all non-zero elements forward and fill the remaining positions with zeros. Steps: Use a pointer insert_pos to track where the next non-zero element should go Traverse the array: If the element is non-zero, place it at insert_pos and move the pointer forward After traversal, fill the rest of the array with 0s This keeps the order intact and avoids extra space. Complexity: Time Complexity: O(n) Space Complexity: O(1) def moveZeroes ( nums ): insert_pos = 0 for num in nums : if num != 0 : nums [ insert_pos ] = num insert_pos += 1 for i in range ( insert_pos , len ( nums )): nums [ i ] = 0 return nums nums = [ 0 , 1 , 0 , 3 , 12 ] print ( moveZeroes ( nums ))

Continue reading on Dev.to Tutorial

Opens in a new tab

Read Full Article
0 views

Related Articles

Topical Dancer is propulsive, playful, and political
News

Topical Dancer is propulsive, playful, and political

The Verge • 14m ago

The SEC drops its four-year-old investigation into EV startup Faraday Future
News

The SEC drops its four-year-old investigation into EV startup Faraday Future

TechCrunch • 2h ago

Why the U.S. and Israel Want the World to Believe Iran Can Strike Europe
News

Why the U.S. and Israel Want the World to Believe Iran Can Strike Europe

Medium Programming • 2h ago

Bridging Quantitative Theory and the Harsh Reality of Commodities
News

Bridging Quantitative Theory and the Harsh Reality of Commodities

Medium Programming • 2h ago

Fear and Loathing in the vibe-coding abyss
News

Fear and Loathing in the vibe-coding abyss

Lobsters • 2h ago

Discover More Articles