Facebook Interview Question for Solutions Engineers
- 1of 1 vote
You are given an array of integers.- Nerd March 16, 2017 in Europe
Write an algorithm that brings all nonzero elements to the left of the array, and returns the number of nonzero elements.
The algorithm should operate in place, i.e. shouldn't create a new array.
The order of the nonzero elements does not matter. The numbers that remain in the right portion of the array can be anything.
given the array [ 1, 0, 2, 0, 0, 3, 4 ],
a possible answer is [ 4, 1, 3, 2, ?, ?, ? ], 4 non-zero elements, where "?" can be any number.
Code should have good complexity and minimize the number of writes to the array.
| Report Duplicate | Flag | PURGE
Facebook Solutions Engineer Coding
Interview Type: Phone Interview
Open Chat in New Window