< Back to notes

Browse 10 notes tagged array.

#array

LeetCode 152: Why maximum product subarray needs both extremes

My Maximum Product Subarray attempt, the counterexample that broke it, and the final O(n) maximum-and-minimum state solution with an invariant and brute-force checks.

LeetCode 53: Maximum subarray without rescanning every starting point

My O(n²) backward scan and final O(n) solution, with the distinction between endingHere and best, all-negative inputs, loop invariants, and executable tests.

LeetCode 11: Container With Most Water in TypeScript, Why Move the Shorter Side?

My two-pointer solution, with a brute-force comparison, a proof for discarding the shorter side, and executable checks for O(n) time and O(1) extra space.

LeetCode 1: Two Sum in TypeScript with a Map

Replace nested pair checks with a Map of earlier values and indices, then explain complement lookup, the loop invariant, and expected O(n) time.

LeetCode 217: Contains Duplicate in TypeScript with a Set

Compare a Set's size with the array length, or stop early during one scan, while explaining the Set solution's correctness and expected O(n) complexity.

LeetCode 121: Best Time to Buy and Sell Stock in TypeScript

Replace nested transaction checks with one scan that tracks the lowest purchase price, including the correctness argument for a two-pointer solution and its O(n) cost.

LeetCode 2574: Left and Right Sum Differences in TypeScript

Compare stored left and right sums with a single scan, including output space, auxiliary space, and the loop invariant.

LeetCode 724: Find a Pivot Index in TypeScript

Find the leftmost pivot index with a total sum and one running left sum, then make the loop invariant and O(n) analysis explicit.

LeetCode 1732: Find the Highest Altitude in TypeScript

Track current altitude and the highest altitude so far in one scan with O(n) time and O(1) auxiliary space.

LeetCode 1480: Running Sum in TypeScript

Use each completed array position as state for one linear scan, with an honest discussion of in-place mutation, the loop invariant, and O(n) time.