~/problems
Problems
Basics first, then the classics, then company-style assessments. Every problem has tests you run right here; multi-level ones unlock as you go. See the roadmap.
Euler tour of a tree
Flatten subtrees into contiguous ranges with tin/tout.
Notes
Recognise it when: you need subtree queries or updates. Flatten the tree so every subtree is a contiguous range.
A DFS assigns tin[v] on entry and tout[v] after the children. The subtree of v is exactly [tin[v], tout[v]), and range structures (Fenwick or segment tree) then answer subtree sums.
Gotchas: use an iterative DFS for deep trees.
4 problems
Advanced & competitive
Tree techniques Binary lifting, LCA, Euler tours.
Euler tour of a tree
- Basics: entry and exit times (tin / tout) basics py · c++ · java easy
- Upstream or downstream? py · c++ · java easy
- Subtree sums with updates medium
- Root-to-node path sums with updates medium