class Solution:
def findTarget(self, root: Optional[TreeNode], k: int) -> bool:
return self.helper(root,set(),k)
def helper(self,node,container,k):
if node is None:
return False
if (k - node.val) in container:
return True
container.add(node.val)
return self.helper(node.left,container,k) or self.helper(node.right,container,k)
Context about the Code - This is from Leetcode problem 653. Two Sum IV - Input is a BST.
Problem Description: We are supposed to find two nodes which sum up to k:inp, if any such node exists we return BOOL -True else: False
return self.helper(node.left,container,k) or self.helper(node.right,container,k)
Can someone help how this above line of code is working in the background, as in, will the left - subtree call will be executed completely before moving to the right subtree traversal (on the right of OR operator) or is it that both the subtrees are traversed at the same time simultaneously with the OR operator.
Also won't there be two sub-sets created for for every left and right subtree when they are called and if so they're created, how is the code checking in on the other subset present in other half of the tree if there's a compliment present in that other half of the recursive call. Very confused, help appreciated.