title: Count Strings Adjacent Characters Difference One
signature: long long countStringsAdjacentCharactersDifferenceOne(int n) {
test_code: #include <algorithm>
  #include <assert.h>
  #include <cstdlib>
  #include <iostream>
  #include <map>
  #include <set>
  #include <string>
  #include <tuple> 
  #include <unordered_map>
  #include <vector>
  #include <math.h>
  #include <cmath>
  #include <bits/stdc++.h>
  #include <numeric>
  #include <functional>
  
  using namespace std;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(long long actual, long long expected){
      return actual == expected;
  }
  
  string driver(int n, long long expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){
              return "PASSED";
          }
          return "FAILED";
      }
      catch (const std::overflow_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::runtime_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::exception& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (...)
      {
          return "UNK_ERROR";
      }
  }
  
  int main() {
      string result = "";
  
      result = driver(7, 1468); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver(47, 1134264891541288); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver(56, 544505079089235836); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver(22, 41103600); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
source_py: def count_strings_adjacent_characters_difference_one(n):
      dp = [[0 for j in range(27)] for i in range((n + 1))]
      for i in range(0, 26):
          dp[1][i] = 1
      for i in range(2, (n + 1)):
          for j in range(0, 26):
              if (j == 0):
                  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 i in range(0, 26):
          sum = (sum + dp[n][i])
      return sum
source_cpp: int count_strings_adjacent_characters_difference_one(int n) {
    long int dp [ n + 1 ] [ 27 ];
    memset ( dp, 0, sizeof ( dp ) );
    for ( int i = 0;
    i <= 25;
    i ++ ) dp [ 1 ] [ i ] = 1;
    for ( int i = 2;
    i <= n;
    i ++ ) {
      for ( int j = 0;
      j <= 25;
      j ++ ) if ( j == 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ];
      else dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] );
    }
    long int sum = 0;
    for ( int i = 0;
    i <= 25;
    i ++ ) sum = ( sum + dp [ n ] [ i ] );
    return sum;
  }