Fragen aus Vorstellungsgesprächen für software engineer, von Bewerbern geteilt
Given an array, without using extra space, move all zeros to the end and no-zeros to the beginning. The function should return the number of non-zeros.
Quick sort the count the zeros ...
Quicksort doesn’t satisfy the requirements because it’s not a sort-in-place algorithm. The correct solution is to use insertion sort.
swapping 2 numbers if one is zero, can be done without any space. assuming array[a] is zero, and array [b] is non zero, array[a] = array[b], array[b] = 0 would simply work. so, have 2 pointers, one from beginning and one from the end, do a while loop