Community

Ask A Question


Notifications
Subscribe You’re not receiving notifications from this thread.

Zeros To The End (Main Thread)

Here is the interview question prompt, presented for reference.

Write a method that moves all zeros in an array to its end. You should maintain the order of all other elements. Here's an example:

js zerosToEnd([1, 0, 2, 0, 4, 0]) // [1, 2, 4, 0, 0, 0]

Here's another one:

js zerosToEnd([1, 0, 2, 0, 4, 0]) // [1, 2, 4, 0, 0, 0]

Fill in the following function signature:

js function zerosToEnd(nums) { return; };

Can you do this without instantiating a new array?

Constraints

  • Length of the array <= 100000
  • The array will always contain integer values between -2147483648 and 214748364
  • Expected time complexity : O(n)
  • Expected space complexity : O(1)

You can see the full challenge with visuals at this link.

Challenges • Asked 8 months ago by Anonymous

Jake from AlgoDaily Commented on May 26, 2020:

This is the main discussion thread generated for Zeros To The End.

Anonymous Commented on May 26, 2020:

The coding language choices are only javascript and python. It would be really nice if we could have C++ too.

Anonymous Commented on May 27, 2020:

[deleted]

Jake from AlgoDaily Commented on Aug 11, 2020:

C++ is coming soon, probably this spring 2021.