title: Sum Nodes K Th Level Tree Represented String
signature: pub fn sum_nodes_k_th_level_tree_represented_string(tree: String, k: i32) -> i32 {
test_code: use std::collections::HashMap;
  use std::collections::HashSet;
  use std::cmp::*;
  use std::collections::*;
  use std::fmt::*; 
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  pub fn validate_solution(actual: i32, expected: i32)->bool{
  return actual==expected
  }
  pub fn driver(tree: String, k: i32, expected: i32)->String{
      if validate_solution(PLACEHOLDER_FN_NAME(tree, k), expected) {
        return "PASSED".to_string();
      };
      return "FAILED".to_string();
  
  }
  
  fn main() {
      println!("TEST-0...{}", driver(
        "(0(5(6()())(4()(9()())))(7(1()())(3()())))".to_string(), 2, 
        14
      ));
      
      println!("TEST-1...{}", driver(
        "(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))".to_string(), 3, 
        9
      ));
      
      println!("TEST-2...{}", driver(
        "(0(5(6()())(4()(9()())))(7(1()())(3()())))".to_string(), 1, 
        12
      ));
      
      println!("TEST-3...{}", driver(
        "(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))".to_string(), 2, 
        16
      ));
      
      println!("TEST-4...{}", driver(
        "(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))".to_string(), 4, 
        0
      ));
      
      println!("TEST-5...{}", driver(
        "(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))".to_string(), 100, 
        0
      ));
      
      println!("TEST-6...{}", driver(
        "(0(5(6()())(4()(9()())))(7(1()())(3()())))".to_string(), 3, 
        9
      ));
      
      println!("TEST-7...{}", driver(
        "(0(5(6()())(4()(9()())))(7(1()())(3()())))".to_string(), 0, 
        0
      ));
      
      println!("TEST-8...{}", driver(
        "0010".to_string(), 12, 
        0
      ));
      
      println!("TEST-9...{}", driver(
        "kjtdgmy".to_string(), 97, 
        0
      ));
      
  }
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;
  }