Facebook Interview Question
Approach 1: go from back or go from front
Move non-zero elements in int array to the left and return number of non-zero elements in the original array.
The order of the non-zero elements is not important. What is left on the right side of the array is not important. Minimize written to array.
//[1, 0, 3, 0, 0, 4] -> [1, 4, 3, 0, 0, 0]

Use similar partition algorithm like quicksort partition array
1. Use two indexes to keep track the zero element and non-zero element
2. Initialize the two indexes to be last index
3. One index is decreased by one only if other index is zero element

// move all zeros to the right side of array
    // [1, 0, 3, 0] => [1, 3, 0, 0]
    public static void partition(Integer[] arr){
        if(arr != null){
            int zeroIndex = 0;
            int len = arr.length;
            for(int i=0; i<len; i++){
                if(arr[i].intValue() > 0){
                    if(i != zeroIndex)
                        swap(arr, i, zeroIndex);
                    // make sure the zeroIndex is not out of bounds
                    if(zeroIndex < len-1)
                        zeroIndex++;
                }
            }
        }
    }
static void partition(Integer[] arr){
        if(arr != null){
            int len = arr.length;
            int nonzero = len-1;
            for(int i=len-1; i >= 0; i--){
                if(arr[i] == 0){
                    int tmp = arr[i];
                    arr[i] = arr[nonzero];
                    arr[nonzero] = tmp;
                    nonzero--;
                }
            }
        }
    }
Quicksort partition technic
// partition the array with pivot
    public static int partition(int[] arr, int lo, int hi){
        int big = lo;
        if(arr != null && lo < hi){
            int pivot = arr[hi];
            for(int i=lo; i<=hi; i++){
                if(arr[i] <= pivot){
                    Aron.swap(arr, big, i);
                    if(i < hi)
                        big++;
                }
            }
        }
        return big;
    }

Given two words, determine if there is a path to get from word A to word B by changing one letter at a time to create valid intermediate words.
For example:
BARK -> BACK -> RACK -> RANK
r->c
b-r
c-n
Inputs are
- Start word
- End word
- Set of valid words
- Return path of words [inclusive]