Small Permutation Leetcode Solution