Google Coding Interview Question - Convert An Array To Reduced Form