26. Segment Tree, Fenwick & Sparse Table
Range queries with point updates.
π¬ Episodes 98β100: video coming soon
Your progress0 of 6
0easy
2medium
4hard
Understand the topic
A prefix sum makes range queries fast, but then every update costs O(n). These structures make both queries and updates O(log n).
A Fenwick tree (Binary Indexed Tree) stores partial sums in an array; i & -i decides how far each step jumps, and it's perfect for prefix sums and counts. A segment tree stores the answer for every range in a binary tree; it handles sum, min and max, and with lazy propagation also range updates. A sparse table answers static range-minimum queries in O(1) after O(n log n) preprocessing.
| # | Problem | Pattern | Level | ||
|---|---|---|---|---|---|
| 1 | Range Sum Query - Mutable #307 | Fenwick tree (BIT) | Medium | LeetCode β | |
| 2 | My Calendar I #729 | Ordered map (floor / ceiling) | Medium | LeetCode β | |
| 3 | Count of Range Sum #327 | Fenwick tree over compressed prefix sums | Hard | LeetCode β | |
| 4 | Create Sorted Array through Instructions #1649 | Fenwick tree counting | Hard | LeetCode β | |
| 5 | Falling Squares #699 | Segment tree with range assign / range max | Hard | LeetCode β | |
| 6 | Longest Increasing Subsequence II #2407 | Segment tree over values (range max) | Hard | LeetCode β |
Nothing matches that filter.
Work top to bottom β each list goes from easy to hard. Try a problem for at least 15 minutes before opening a hint. Ticks are saved in your browser.