Permutation Game Hackerrank Solution