title: Number Of Binary Trees For Given Preorder Sequence Length
signature: function numberOfBinaryTreesForGivenPreorderSequenceLength(n: number): number {
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.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}}]
question_info.entry_cls_name: Solution
question_info.test_code: 
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function convertToString(value: any): string{
      return JSON.stringify(value, function (key, val) {
          if (val instanceof Set) {
              return Array.from(val);
          } return val;});
  }
  
  function validateSolution(actual: number, expected: number): boolean {
      return convertToString(actual) === convertToString(expected);
  }
  
  function driver(n: number, expected:number): string {
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(n),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    result = driver(15, 9694845);
    console.log(`TEST-0...${result}`);
  
    result = driver(11, 58786);
    console.log(`TEST-1...${result}`);
  
    result = driver(11, 58786);
    console.log(`TEST-2...${result}`);
  
    result = driver(15, 9694845);
    console.log(`TEST-3...${result}`);
  
  };
  
  main();
question_info.extension: ts
question_info.entry_fn_name: numberOfBinaryTreesForGivenPreorderSequenceLength
question_info.test_case_ids: 0 1 2 3
question_info.commands: tsc --target es2020 --lib es5,dom,es2015,es2020 __FILENAME__
question_info.commands: node __FILENAME__.js