Permutation Game Hackerrank Sql