Dp

14 articles

dsa6 min read

House Robber III — Tree DP with Pair Return (LC 337)

LC 337 House Robber III extends the classic House Robber DP to a binary tree where adjacent nodes cannot both be robbed. The optimal O(n) solution uses post-order DFS returning a (rob, skip) pair — a fundamental tree DP pattern tested at Amazon and Microsoft.

Read →
dsa6 min read

Kth Ancestor of a Tree Node — LC 1483 Binary Lifting

LC 1483 Kth Ancestor of a Tree Node answers each query in O(log k) after O(n log n) preprocessing using binary lifting — a sparse table DP technique that also powers LCA algorithms and is commonly tested at Amazon.

Read →