gary@interview:~/interview/coding/967-numbers-with….md$
$ cat ./coding/967-numbers-with-same-consecutive-differences.md
[Coding]

967. Numbers With Same Consecutive Differences

────────────────────────────────────────────────────────────

967. Numbers With Same Consecutive Differences

class Solution:
    def numsSameConsecDiff(self, n: int, k: int) -> List[int]:
        
        res = []
        
        def backtrack(curr, digit):
            if digit == n:
                res.append(curr)
                return res

            for i in range(10):
                if digit == 0 and i == 0: # leading zero
                    continue
                if digit > 0 and abs(i - curr % 10 ) != k: # Diff is not k
                    continue
                
                curr = curr * 10 + i
                digit += 1
                backtrack(curr, digit)
                curr = curr // 10
                digit -= 1
        
        backtrack(0, 0)

        return res
--tags#Backtrack
$ ls ./coding/ | grep -v 967-numbers-with-same-consecutive-differences
265. Paint House II256. Paint House143. Reorder List1762. Buildings With an Ocean View
← cd ../codingcd ~