Permutation question done using ArrayList