Swapped solution isPermutation for the alternative solution (not using permutations)