title: Product Nodes K Th Level Tree Represented String
signature: func productNodesKThLevelTreeRepresentedString(tree string, k int) int {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual int, expected int) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(tree string, k int, expected int) string {
      if validateSolution(PLACEHOLDER_FN_NAME(tree, k),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver("(0(5(6()())(4()(9()())))(7(1()())(3()())))", 
  	2, 72)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver("(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", 
  	3, 15)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver("(0(5(6()())(4()(9()())))(7(1()())(3()())))", 
  	1, 35)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver("(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", 
  	2, 0)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver("(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", 
  	4, 1)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver("(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", 
  	100, 1)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver("(0(5(6()())(4()(9()())))(7(1()())(3()())))", 
  	3, 9)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver("(0(5(6()())(4()(9()())))(7(1()())(3()())))", 
  	0, 0)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver("0010", 
  	12, 1)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver("kjtdgmy", 
  	97, 1)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
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;
  }