All posts
dsa
Sum any range in one subtraction
A precompute that takes O(n) once and turns every future range-sum query into a single subtraction — no matter how wide the range. The pattern feels illegal until you've built it.
dsaStop re-adding the same numbers
Brute force keeps re-adding the same overlapping numbers thousands of times. The sliding window updates with exactly two operations — no matter how wide the window. Here's the pattern, and where it goes next.
dsaHow to find the best streak in a single pass
There are millions of possible streaks in your data. Kadane's algorithm finds the single best one without checking almost any of them — here's the one idea that makes it work.
dsaThe nested loop you can almost always delete
Two pointers turns an O(n²) pair-search into a single elegant pass over a sorted array — and here's the intuition for why it can never miss.