title: Sum Nodes K Th Level Tree Represented String
signature: fun sumNodesKThLevelTreeRepresentedString(tree: String, k: Int): Int {
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;
  }
question_info.test_list: [{"idx": 0, "outputs": 14, "inputs": {"tree": "(0(5(6()())(4()(9()())))(7(1()())(3()())))", "k": 2}}, {"idx": 1, "outputs": 9, "inputs": {"tree": "(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", "k": 3}}, {"idx": 2, "outputs": 12, "inputs": {"tree": "(0(5(6()())(4()(9()())))(7(1()())(3()())))", "k": 1}}, {"idx": 3, "outputs": 16, "inputs": {"tree": "(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", "k": 2}}, {"idx": 4, "outputs": 0, "inputs": {"tree": "(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", "k": 4}}, {"idx": 5, "outputs": 0, "inputs": {"tree": "(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", "k": 100}}, {"idx": 6, "outputs": 9, "inputs": {"tree": "(0(5(6()())(4()(9()())))(7(1()())(3()())))", "k": 3}}, {"idx": 7, "outputs": 0, "inputs": {"tree": "(0(5(6()())(4()(9()())))(7(1()())(3()())))", "k": 0}}, {"idx": 8, "outputs": 0, "inputs": {"tree": "0010", "k": 12}}, {"idx": 9, "outputs": 0, "inputs": {"tree": "kjtdgmy", "k": 97}}]
question_info.extension: kts
question_info.test_code: package main
  
  import kotlin.text.*
  import kotlin.math.*
  
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  fun validateSolution(actual:Int, expected:Int):Boolean{
    return actual.equals(expected)
  }
  fun driver(tree: String, k: Int, expected:Int):String {
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME(tree, k), expected)) {
                return "PASSED"
        }
        return "FAILED"
      } catch (e: Exception){
        return e::class.simpleName as String
      }
  
  }
  
  fun main() {
      var result: String = ""
      result = driver("(0(5(6()())(4()(9()())))(7(1()())(3()())))", 2, 14)
      println("TEST-0...${result}")
      
      result = driver("(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", 3, 9)
      println("TEST-1...${result}")
      
      result = driver("(0(5(6()())(4()(9()())))(7(1()())(3()())))", 1, 12)
      println("TEST-2...${result}")
      
      result = driver("(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", 2, 16)
      println("TEST-3...${result}")
      
      result = driver("(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", 4, 0)
      println("TEST-4...${result}")
      
      result = driver("(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", 100, 0)
      println("TEST-5...${result}")
      
      result = driver("(0(5(6()())(4()(9()())))(7(1()())(3()())))", 3, 9)
      println("TEST-6...${result}")
      
      result = driver("(0(5(6()())(4()(9()())))(7(1()())(3()())))", 0, 0)
      println("TEST-7...${result}")
      
      result = driver("0010", 12, 0)
      println("TEST-8...${result}")
      
      result = driver("kjtdgmy", 97, 0)
      println("TEST-9...${result}")
      
          
  }
  
  main()
question_info.entry_fn_name: sumNodesKThLevelTreeRepresentedString
question_info.entry_cls_name: Solution
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: kotlinc -script __FILENAME__ -no-reflect -nowarn