Smallest Number Following Pattern Leetcode 753