dsa1 min read
My Calendar III — Difference Array / Seg Tree
Track maximum booking overlaps at any time. Difference array: +1 at start, -1 at end; running max of prefix sum. Lazy segment tree for dynamic range.
Read →
webcoderspeed.com
1276 articles
Track maximum booking overlaps at any time. Difference array: +1 at start, -1 at end; running max of prefix sum. Lazy segment tree for dynamic range.
Find max rectangle sum <= k in 2D matrix. Fix row boundaries, compress to 1D array, use prefix sums + BIT/sorted set to find best subarray sum <= k.
Find longest subarray with sum <= k. Build prefix sums, use monotonic deque for decreasing prefix sums to efficiently find left boundaries.
For each element compute product of all other elements. Two-pass: left prefix products then multiply with right suffix products.
Complete Segment Tree and BIT cheatsheet: templates for BIT, segment tree, lazy propagation, 2D BIT, and problem index.