correctly implemented Common Permutations problem