content: class Solution {
  
      public int[] numsSameConsecDiff(int N, int K) {
  
          if (N == 1)
              return new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  
          List<Integer> queue = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
          for(int level = 1; level < N; ++ level) {
              ArrayList<Integer> nextQueue = new ArrayList<>();
              // iterate through each number within the level
              for (Integer num : queue) {
                  Integer tailDigit = num % 10;
  
                  ArrayList<Integer> nextDigits = new ArrayList<>();
                  nextDigits.add(tailDigit + K);
                  if (K != 0)
                      nextDigits.add(tailDigit - K);
                  for (Integer nextDigit : nextDigits) {
                      if (0 <= nextDigit && nextDigit < 10) {
                          Integer newNum = num * 10 + nextDigit;
                          nextQueue.add(newNum);
                      }
                  }
              }
              // prepare for the next level
              queue = nextQueue;
          }
  
          return queue.stream().mapToInt(i->i).toArray();
      }
  }