A queue of pairs to do bfs traversal and keep track if the node is a left or right child if boolean value is true then it is a left child .
q = deque ( ) NEW_LINE q . append ( [ root , 0 ] ) NEW_LINE sum = 0 NEW_LINE