dsa1 min read
Max Sum Rectangle No Larger than K — BIT + Prefix
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.
Read →
1575 articles
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.
Master every stack and queue pattern: monotonic stack, BFS, two-stack tricks, deque, and design — with templates and full index of 50 problems.