All Posts

1276 articles

dsa3 min read

Sum of Distances in Tree

Compute sum of distances from every node to all others in O(n) using two DFS passes with rerooting technique.

Read →
dsa2 min read

Unique Binary Search Trees

Count the number of structurally unique BSTs with n nodes using Catalan numbers and DP.

Read →
dsa1 min read

Binary Tree Pruning

Remove all subtrees that do not contain a 1 by recursively returning null for subtrees with only zeros.

Read →
Page 107 of 256