Array & String Foundations

  • Arrays are contiguous: optimize by indexing and in-place updates.
  • Invariants drive correctness: define what stays true before coding.

Core patterns

  • Read/Write compaction (remove, dedupe)
  • Two pointers from ends (merge, swap, symmetry)
  • Rotation via reverse (3-step reverse trick)
  • Single-pass greedy scans (min so far / farthest reach)
  • Counting and selection (Boyer-Moore, H-index buckets)
  • Prefix/Suffix products (exclude self)

Common pitfalls

  • Off-by-one on empty or single-element arrays
  • Overwrite bugs when merging from the front
  • Forgetting k %= n for rotation
  • Returning a new slice instead of new length
1 / 1
Use arrow keys or click edges to navigate. Press H to toggle help, F for fullscreen.