Permutation Problem On Leetcode Interview