🎉 All 30 days are live — the full DSA-30 course, from Big-O to System Design. See the roadmap →
Day 19 - Segment TreesPractice QuestionsOverview

Segment Tree & BIT Practice Questions

Eight problems spanning the whole toolkit: point-update segment trees, range-minimum, lazy propagation, value-indexed BITs with coordinate compression, 2D, and interval-overlap. Once you’ve done these, “range query on a changing array” is a solved problem for you.

The recognition checklist:

  1. Repeated range queries on a mutable array → segment tree or BIT.
  2. Only prefix/range sums → BIT (shorter); min/max/gcd → segment tree.
  3. Range updates (add to a whole range) → lazy propagation.
  4. “How many smaller / in range” counting → value-indexed BIT + coordinate compression.
  5. Overlapping intervals / “max overlap” → segment tree on compressed coordinates (or a sweep line).

Medium

ProblemPatternStatus
Range Sum Query — Mutablethe canonical point-update sum tree / BITAvailable
Range Minimum Querysegment tree with min aggregateAvailable
Range Additiondifference array / range-update lazyAvailable

Hard

ProblemPatternStatus
Count of Smaller Numbers After Selfvalue-indexed BIT, right-to-leftAvailable
Reverse PairsBIT / segment tree with compressionAvailable
Range Sum Query 2D — Mutable2D Fenwick treeAvailable
My Calendar IIImax-overlap, sweep / lazy segment treeAvailable
Falling Squareslazy range-assign + coordinate compressionAvailable

More Practice (Coming Soon)

ProblemPatternStatus
Count of Range SumBIT on prefix sumsComing Soon
The Skyline Problemsegment tree / sweepComing Soon
Number of Longest Increasing Subsequencesegment tree on valuesComing Soon
Range Moduleinterval segment treeComing Soon
Rectangle Area IIsweep line + segment treeComing Soon
Queue Reconstruction by Heightorder-statistic BITComing Soon
Maximum Sum of 3 Non-Overlapping Subarraysprefix + segment treeComing Soon
Shifting Letters / Range XORBIT of XORComing Soon