Smallest Number Following Pattern Leetcode 759