Smallest Number Following Pattern Leetcode Sql