Pattern Problem In Leetcode Solutions Python