[algorithm.is_permutation] Reduce complexity