text: Product of nodes at k | JavaScript implementation to find product of elements at k - th level ; 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
code: var i ; function productAtKthLevel ( tree , k , level ) { if ( tree [ i ++ ] == ' ' ) { if ( tree [ i ] == ' ' ) return 1 ; var product = 1 ; if ( level == k ) product = tree [ i ] - ' ' ; ++ i ; var leftproduct = productAtKthLevel ( tree , k , level + 1 ) ; ++ i ; var rightproduct = productAtKthLevel ( tree , k , level + 1 ) ; ++ i ; return product * leftproduct * rightproduct ; } return int . MinValue ; } var tree = " " ; var k = 2 ; i = 0 ; document . write ( productAtKthLevel ( tree , k , 0 ) ) ;