Refactor permutation check to handle larger nums.