Alternating Groups Leetcode Python