Smallest Number Following Pattern Leetcode Python Coding