title: Product Nodes K Th Level Tree Represented String
signature: function product_nodes_k_th_level_tree_represented_string(tree, k)
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;
  }
question_info.entry_fn_name: product_nodes_k_th_level_tree_represented_string
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(tree, k, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(tree, k) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver("(0(5(6()())(4()(9()())))(7(1()())(3()())))", 2, 72)
      print(string.format("TEST-0...%s",result))
  
      result = driver("(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", 3, 15)
      print(string.format("TEST-1...%s",result))
  
      result = driver("(0(5(6()())(4()(9()())))(7(1()())(3()())))", 1, 35)
      print(string.format("TEST-2...%s",result))
  
      result = driver("(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", 2, 0)
      print(string.format("TEST-3...%s",result))
  
      result = driver("(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", 4, 1)
      print(string.format("TEST-4...%s",result))
  
      result = driver("(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", 100, 1)
      print(string.format("TEST-5...%s",result))
  
      result = driver("(0(5(6()())(4()(9()())))(7(1()())(3()())))", 3, 9)
      print(string.format("TEST-6...%s",result))
  
      result = driver("(0(5(6()())(4()(9()())))(7(1()())(3()())))", 0, 0)
      print(string.format("TEST-7...%s",result))
  
      result = driver("0010", 12, 1)
      print(string.format("TEST-8...%s",result))
  
      result = driver("kjtdgmy", 97, 1)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": 72, "inputs": {"tree": "(0(5(6()())(4()(9()())))(7(1()())(3()())))", "k": 2}}, {"idx": 1, "outputs": 15, "inputs": {"tree": "(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", "k": 3}}, {"idx": 2, "outputs": 35, "inputs": {"tree": "(0(5(6()())(4()(9()())))(7(1()())(3()())))", "k": 1}}, {"idx": 3, "outputs": 0, "inputs": {"tree": "(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", "k": 2}}, {"idx": 4, "outputs": 1, "inputs": {"tree": "(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))", "k": 4}}, {"idx": 5, "outputs": 1, "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": 1, "inputs": {"tree": "0010", "k": 12}}, {"idx": 9, "outputs": 1, "inputs": {"tree": "kjtdgmy", "k": 97}}]