Trees Flashcards
1
Q
Vertical Order
A
- two queue “q” to process the element to get the “col “for the element
- Maintain map of column and lists use the col to get lsit and add value;
- If left, add it q and add it col q with col - 1, min(min, col - 1)
- for its col + 1 and max(max, col - 1)
- Finally iterate from the min to max and get the list from the hashmap and add it to the result
2
Q
Sum of root to leaf node
A
- recursive(root, sum)
- sum += sum * 10 + root.val
- recursive(left, sum) + recursive(right, sum)