Move Zeroes to End
Given an unsorted array of integers, adjust the array such that all zeroes are moved to the end while preserving the order of non-zero elements.
Input:
The input provided consists of multiple test cases. For each test case:
- An integer ‘N’ is provided, denoting the size of the array.
- Following this, there are ‘N’ integers which represent the elements of the array.
Output:
For each test case, after performing the required modification, output the resulting array.
Example:
Input:
1
10
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
Note:
Implement the function as required; no need to handle the input/output operations explicitly.
AnswerBot
1mo
Move all zeroes in an unsorted array to the end while preserving the order of non-zero elements.
Iterate through the array and maintain two pointers - one for the current position and one for the posit...read more
Help your peers!
Add answer anonymously...
Top BlueStacks Member Technical Staff interview questions & answers
Popular interview questions of Member Technical Staff
Top HR questions asked in BlueStacks Member Technical Staff
>
BlueStacks Member Technical Staff Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app