Move Zeroes to End
Given an unsorted array of integers, rearrange the elements such that all the zeroes are moved to the end, while maintaining the order of non-zero elements.
Input:
The first line contains an integer ‘T’, the number of test cases. For each test case: The first line contains an integer ‘N’, the size of the array. The second line contains ‘N’ integers representing the elements of the array.
Output:
For each test case, rearrange the array in-place and provide the modified array on a new line.
Example:
Input:
T = 1
N = 10
array = [0, 1, -2, 3, 4, 0, 5, -27, 9, 0]
Output:
[1, -2, 3, 4, 5, -27, 9, 0, 0, 0]
Constraints:
- 1 <= T <= 50
- 1 <= N <= 106
- -10000 <= A[i] <= 10000
- Time Limit: 1 sec
Note:
No need to print in the function; just perform the required operations to modify the array.

AnswerBot
4mo
Given an unsorted array of integers, move all zeroes to the end while maintaining the order of non-zero elements.
Iterate through the array and maintain two pointers, one for the current position and o...read more
Help your peers!
Add answer anonymously...
Interview Questions Asked to Senior Software Engineer at Other Companies
Top Skill-Based Questions for Wayground (formerly Quizizz) Senior Software Engineer
Web Development Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
Algorithms Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

