human
What is a code to product of nodes at k and the other steps required given the following:
Product of nodes at k | Recursive Function to find product of elements at k - th level.
if subtree is null , just like if root == NULL.
Consider only level k node to be part of the product.
Recur for Left Subtree.
Recur for Right Subtree.
Taking care of ' ) ' after left and right subtree.
Driver Code"
Solution in Python:
assistant
#Here is code to product of nodes at k and the other steps required.
 def productAtKthLevel ( tree , k , i , level ) :
	if ( tree [ i [ 0 ] ] == ' ( ' ) :
		i [ 0 ] += 1
		if ( tree [ i [ 0 ] ] == ' ) ' ) :
			return 1
		product = 1
		if ( level == k ) :
			product = int ( tree [ i [ 0 ] ] )
		i [ 0 ] += 1
		leftproduct = productAtKthLevel ( tree , k , i , level + 1 )
		i [ 0 ] += 1
		rightproduct = productAtKthLevel ( tree , k , i , level + 1 )
		i [ 0 ] += 1
		return product * leftproduct * rightproduct
if __name__ == " _ _ main _ _ " :
	tree = " ( 0(5(6 ( ) ( ) ) ( 4 ( ) (9 ( ) ( ) ) ) ) ( 7(1 ( ) ( ) ) ( 3 ( ) ( ) ) ) ) "
	k = 2
	i = [ 0 ]
	print ( productAtKthLevel ( tree , k , i , 0 ) )