dsa2 min read
Longest ZigZag Path in Binary Tree
Find the longest zigzag path in a binary tree where you alternate left-right directions at each step.
Read →
webcoderspeed.com
1276 articles
Find the longest zigzag path in a binary tree where you alternate left-right directions at each step.
Compute sum of distances from every node to all others in O(n) using two DFS passes with rerooting technique.
Count the number of structurally unique BSTs with n nodes using Catalan numbers and DP.
Perform level-order traversal of an N-ary tree using BFS, collecting all children at each level.
Remove all subtrees that do not contain a 1 by recursively returning null for subtrees with only zeros.