Skip to content
All tags

#arrays

5 entries tagged #arrays

  • Valid Triangle Number

    Post · Apr 16, 2026

    Count how many triplets of side lengths can form a triangle. Testing every triple is n³; sorting plus one observation lets a single comparison count a whole batch of triangles at once.

  • 3Sum

    Post · Apr 10, 2026

    Find every triplet that sums to zero, without listing any twice. Three unknowns become two once you fix one, and the hard part turns out to be the duplicates, not the search.

  • Two Sum II

    Post · Apr 05, 2026

    Two pointers on a sorted array finds the pair in one pass. But why is it safe to throw a number away after one bad sum? Draw every pair as a grid and the proof becomes a picture.

  • Container With Most Water

    Post · Mar 30, 2026

    Pick two walls from a row so the water between them is as large as possible. Checking every pair works, but one observation about the shorter wall makes it a single pass.

  • Two Pointers

    Post · Mar 24, 2026

    Checking every pair in an array costs n² comparisons. If the array is sorted, one comparison can rule out a whole row of pairs at once, and the nested loop collapses into a single pass.