title: Product Nodes K Th Level Tree Represented String
signature: productNodesKThLevelTreeRepresentedString(tree, k) {
test_code: import 'dart:convert';
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(int actual, int expected){
      return actual.toString() == expected.toString();
  }
  
  String driver(tree, k, int expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(tree, k), expected)){
              return "PASSED";
          }
          return "FAILED";
      }catch(exception_object){
          return exception_object.runtimeType.toString();
      }
  }
  
  int main() {
  
      print("TEST-0...${driver(
          "(0(5(6()())(4()(9()())))(7(1()())(3()())))", 2, 
          72)
      }");
  
      print("TEST-1...${driver(
          "(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", 3, 
          15)
      }");
  
      print("TEST-2...${driver(
          "(0(5(6()())(4()(9()())))(7(1()())(3()())))", 1, 
          35)
      }");
  
      print("TEST-3...${driver(
          "(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", 2, 
          0)
      }");
  
      print("TEST-4...${driver(
          "(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", 4, 
          1)
      }");
  
      print("TEST-5...${driver(
          "(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", 100, 
          1)
      }");
  
      print("TEST-6...${driver(
          "(0(5(6()())(4()(9()())))(7(1()())(3()())))", 3, 
          9)
      }");
  
      print("TEST-7...${driver(
          "(0(5(6()())(4()(9()())))(7(1()())(3()())))", 0, 
          0)
      }");
  
      print("TEST-8...${driver(
          "0010", 12, 
          1)
      }");
  
      print("TEST-9...${driver(
          "kjtdgmy", 97, 
          1)
      }");
  
      return 0;
  }
source_py: def product_nodes_k_th_level_tree_represented_string(tree, k):
      level = (- 1)
      product = 1
      n = len(tree)
      for i in range(0, n):
          if (tree[i] == '('):
              level += 1
          elif (tree[i] == ')'):
              level -= 1
          elif (level == k):
              product *= (int(tree[i]) - int('0'))
      return product
source_cpp: int product_nodes_k_th_level_tree_represented_string(string tree, int k) {
    int level = - 1;
    int product = 1;
    int n = tree . length ( );
    for ( int i = 0;
    i < n;
    i ++ ) {
      if ( tree [ i ] == '(' ) level ++;
      else if ( tree [ i ] == ')' ) level --;
      else {
        if ( level == k ) product *= ( tree [ i ] - '0' );
      }
    }
    return product;
  }