Smallest Number Following Pattern Leetcode 75