title: Number Of Binary Trees For Given Preorder Sequence Length
signature: function number_of_binary_trees_for_given_preorder_sequence_length(n)
source_py: def number_of_binary_trees_for_given_preorder_sequence_length(n):
      BT = ([0] * (n + 1))
      BT[0] = BT[1] = 1
      for i in range(2, (n + 1)):
          for j in range(i):
              BT[i] += (BT[j] * BT[((i - j) - 1)])
      return BT[n]
source_cpp: int number_of_binary_trees_for_given_preorder_sequence_length(int n) {
    int BT [ n + 1 ];
    memset ( BT, 0, sizeof ( BT ) );
    BT [ 0 ] = BT [ 1 ] = 1;
    for ( int i = 2;
    i <= n;
    ++ i ) for ( int j = 0;
    j < i;
    j ++ ) BT [ i ] += BT [ j ] * BT [ i - j - 1 ];
    return BT [ n ];
  }
question_info.entry_fn_name: number_of_binary_trees_for_given_preorder_sequence_length
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3']
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(15, 9694845)
      print(string.format("TEST-0...%s",result))
  
      result = driver(11, 58786)
      print(string.format("TEST-1...%s",result))
  
      result = driver(11, 58786)
      print(string.format("TEST-2...%s",result))
  
      result = driver(15, 9694845)
      print(string.format("TEST-3...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": 9694845, "inputs": {"n": 15}}, {"idx": 1, "outputs": 58786, "inputs": {"n": 11}}, {"idx": 2, "outputs": 58786, "inputs": {"n": 11}}, {"idx": 3, "outputs": 9694845, "inputs": {"n": 15}}]