Check if each prefix forms 1..k permutation | Uber Interview Question