title: Total Number Of Non Decreasing Numbers With N Digits
signature: function total_number_of_non_decreasing_numbers_with_n_digits(n)
source_py: def total_number_of_non_decreasing_numbers_with_n_digits(n):
      dp = [[0 for i in range((n + 1))] for i in range(10)]
      for i in range(10):
          dp[i][1] = 1
      for digit in range(10):
          for len in range(2, (n + 1)):
              for x in range((digit + 1)):
                  dp[digit][len] += dp[x][(len - 1)]
      count = 0
      for i in range(10):
          count += dp[i][n]
      return count
source_cpp: long long int total_number_of_non_decreasing_numbers_with_n_digits(int n) {
    long long int dp [ 10 ] [ n + 1 ];
    memset ( dp, 0, sizeof dp );
    for ( int i = 0;
    i < 10;
    i ++ ) dp [ i ] [ 1 ] = 1;
    for ( int digit = 0;
    digit <= 9;
    digit ++ ) {
      for ( int len = 2;
      len <= n;
      len ++ ) {
        for ( int x = 0;
        x <= digit;
        x ++ ) dp [ digit ] [ len ] += dp [ x ] [ len - 1 ];
      }
    }
    long long int count = 0;
    for ( int i = 0;
    i < 10;
    i ++ ) count += dp [ i ] [ n ];
    return count;
  }
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(n, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(n) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver(21, 14307150)
      print(string.format("TEST-0...%s",result))
  
      result = driver(40, 2054455634)
      print(string.format("TEST-1...%s",result))
  
      result = driver(83, 868754947060)
      print(string.format("TEST-2...%s",result))
  
      result = driver(93, 2290415157800)
      print(string.format("TEST-3...%s",result))
  
      result = driver(43, 3679075400)
      print(string.format("TEST-4...%s",result))
  
      result = driver(98, 3585446225075)
      print(string.format("TEST-5...%s",result))
  
      result = driver(35, 708930508)
      print(string.format("TEST-6...%s",result))
  
      result = driver(86, 1174992339235)
      print(string.format("TEST-7...%s",result))
  
      result = driver(76, 411731930610)
      print(string.format("TEST-8...%s",result))
  
      result = driver(88, 1429144287220)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 14307150, "inputs": {"n": 21}}, {"idx": 1, "outputs": 2054455634, "inputs": {"n": 40}}, {"idx": 2, "outputs": 868754947060, "inputs": {"n": 83}}, {"idx": 3, "outputs": 2290415157800, "inputs": {"n": 93}}, {"idx": 4, "outputs": 3679075400, "inputs": {"n": 43}}, {"idx": 5, "outputs": 3585446225075, "inputs": {"n": 98}}, {"idx": 6, "outputs": 708930508, "inputs": {"n": 35}}, {"idx": 7, "outputs": 1174992339235, "inputs": {"n": 86}}, {"idx": 8, "outputs": 411731930610, "inputs": {"n": 76}}, {"idx": 9, "outputs": 1429144287220, "inputs": {"n": 88}}]
question_info.extension: lua
question_info.entry_fn_name: total_number_of_non_decreasing_numbers_with_n_digits
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: lua __FILENAME__