title: Sum Nodes K Th Level Tree Represented String
signature: function sumNodesKThLevelTreeRepresentedString($tree, $k) {
test_code: <?php
  
  
  // SOLUTION CODE 
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function validateSolution($actual, $expected){
      return serialize($actual) == serialize($expected);
  }
  
  function driver($tree, $k, $expected){
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME($tree, $k), $expected)){
          return "PASSED";
        }
        return "FAILED";
      }
      catch (Exception $exception_obj) {
        return get_class($exception_obj);
      }
  }
  
  function main(){
      printf("TEST-0...%s\n",driver(
        "(0(5(6()())(4()(9()())))(7(1()())(3()())))", 2, 
        14));
      
      printf("TEST-1...%s\n",driver(
        "(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", 3, 
        9));
      
      printf("TEST-2...%s\n",driver(
        "(0(5(6()())(4()(9()())))(7(1()())(3()())))", 1, 
        12));
      
      printf("TEST-3...%s\n",driver(
        "(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", 2, 
        16));
      
      printf("TEST-4...%s\n",driver(
        "(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", 4, 
        0));
      
      printf("TEST-5...%s\n",driver(
        "(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", 100, 
        0));
      
      printf("TEST-6...%s\n",driver(
        "(0(5(6()())(4()(9()())))(7(1()())(3()())))", 3, 
        9));
      
      printf("TEST-7...%s\n",driver(
        "(0(5(6()())(4()(9()())))(7(1()())(3()())))", 0, 
        0));
      
      printf("TEST-8...%s\n",driver(
        "0010", 12, 
        0));
      
      printf("TEST-9...%s\n",driver(
        "kjtdgmy", 97, 
        0));
      
  }
  
  main();
  ?>
source_py: def sum_nodes_k_th_level_tree_represented_string(tree, k):
      level = (- 1)
      sum = 0
      n = len(tree)
      for i in range(n):
          if (tree[i] == '('):
              level += 1
          elif (tree[i] == ')'):
              level -= 1
          elif (level == k):
              sum += (ord(tree[i]) - ord('0'))
      return sum
source_cpp: int sum_nodes_k_th_level_tree_represented_string(string tree, int k) {
    int level = - 1;
    int sum = 0;
    int n = tree . length ( );
    for ( int i = 0;
    i < n;
    i ++ ) {
      if ( tree [ i ] == '(' ) level ++;
      else if ( tree [ i ] == ')' ) level --;
      else {
        if ( level == k ) sum += ( tree [ i ] - '0' );
      }
    }
    return sum;
  }