title: Number N Digit Stepping Numbers
signature: class Solution {
  
      public long NumberNDigitSteppingNumbers(int n) {
test_code: using System;
  using System.Numerics;
  using System.Diagnostics;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  using System.Web.UI;
  using System.Web.Script.Serialization;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  namespace EvaluatePrediction {
      class TestRunner {
          public bool ValidateSolution(long actual, long expected){
              return new JavaScriptSerializer().Serialize(actual) == new JavaScriptSerializer().Serialize(expected);
          }
  
          public string driver(int n, long expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                long pred_result = solution_cls.PLACEHOLDER_FN_NAME(n); 
                if (ValidateSolution(
                      pred_result,
                      expected)){
                  return "PASSED";
                }
                return "FAILED";
              } 
              catch (Exception exception_obj)
              {
                return exception_obj.GetType().FullName;
              }
          }
          static void Main(string[] args) {
              TestRunner runner = new TestRunner();
              String result;
              result = runner.driver(
                  18, 
                  547810
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  26, 
                  100719775
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  41, 
                  1774846161206
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  20, 
                  2017126
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  25, 
                  52479500
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  52, 
                  2306507126768895
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  13, 
                  21053
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );
          }
      }
  }
  
source_py: def number_n_digit_stepping_numbers(n):
      dp = [[0 for x in range(10)] for y in range((n + 1))]
      if (n == 1):
          return 10
      for j in range(10):
          dp[1][j] = 1
      for i in range(2, (n + 1)):
          for j in range(10):
              if (j == 0):
                  dp[i][j] = dp[(i - 1)][(j + 1)]
              elif (j == 9):
                  dp[i][j] = dp[(i - 1)][(j - 1)]
              else:
                  dp[i][j] = (dp[(i - 1)][(j - 1)] + dp[(i - 1)][(j + 1)])
      sum = 0
      for j in range(1, 10):
          sum = (sum + dp[n][j])
      return sum
source_cpp: long long number_n_digit_stepping_numbers(int n) {
    int dp [ n + 1 ] [ 10 ];
    if ( n == 1 ) return 10;
    for ( int j = 0;
    j <= 9;
    j ++ ) dp [ 1 ] [ j ] = 1;
    for ( int i = 2;
    i <= n;
    i ++ ) {
      for ( int j = 0;
      j <= 9;
      j ++ ) {
        if ( j == 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ];
        else if ( j == 9 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ];
        else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ];
      }
    }
    long long sum = 0;
    for ( int j = 1;
    j <= 9;
    j ++ ) sum += dp [ n ] [ j ];
    return sum;
  }