Binary Tree Consecutive Sequence II

Binary Tree Consecutive Sequence II (Backtracking Solution) Given a binary tree, find the longest consecutive sequence in the binary tree. Note that it can be any direction, rather than only from parent to child as in its previous problem. The idea is to use backtracking. Brush up on backtracking. It it recursion which does recursion […]

Binary Tree Longest Consecutive Sequence

Binary Tree Longest Consecutive Sequence (DFS Solution) The idea is to traverse the binary tree with DFS, meanwhile carry the current consecutive length so far. Also pass in the target, which is current_value + 1 to child recursion call, so that child can compare itself to the target: (1) if child is consecutive, increment the […]