Permutations of Strings in C - Hacker Rank Solution