Numbers With Same Consecutive Differences

Given two integers n and k, return an array of all the integers of length n where the difference between every two consecutive digits is k. You may return the answer in any order.

Note that the integers should not have leading zeros. Integers such as 02 and 043 are not allowed.

Example 1
Inputn = 3, k = 7
Output[181,292,707,818,929]
The number 070 is not valid because it has leading zeroes.
Example 2
Inputn = 2, k = 1
Output[10,12,21,23,32,34,43,45,54,56,65,67,76,78,87,89,98]
Each returned two-digit integer has adjacent digits that differ by 1 and has no leading zero.

Constraints

  • 2 <= n <= 9
  • 0 <= k <= 9

Asked at 5 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate