Skip to main content

πŸ“Š Arrays

Arrays are the foundation of every coding interview. Most interview problems can be reduced to "scan this array efficiently." Master the four core techniques here and you have a tool for ~40% of LeetCode.

This category contains 45 problems. Use the patterns below to recognize what's being asked, then jump to the problem list at the bottom.


🧠 Key Patterns​

  • Two Pointers β€” Sorted array, find pair/triplet, partition. Move two indices inward or in lockstep.
  • Sliding Window β€” Subarray with property (sum, length, distinct). Grow right, shrink left.
  • Binary Search β€” Sorted/monotonic array, search for value or boundary. O(log⁑n)O(\log n).
  • Prefix Sum / Difference Array β€” Range sum queries, count-of-prefix tricks. O(1)O(1) range after O(n)O(n) prep.
  • Hash Map β€” Lookups, frequency counts, complement pairs (e.g. Two Sum).
  • Kadane / DP-on-array β€” Max subarray, contiguous best/worst.

⚠️ Common Pitfalls​

  • Off-by-one in left <= right vs left < right binary search loops.
  • Sliding-window: forgetting to shrink the window when the constraint breaks.
  • Integer overflow in (left + right) / 2 β€” use left + (right - left) / 2.

πŸ“š Study Resources​

πŸ“Ί Videos​

πŸ“– Books​

  • Cracking the Coding Interview β€” Gayle Laakmann McDowell β€” Ch. 1 (Arrays & Strings)
  • Algorithm Design Manual β€” Steven Skiena β€” Ch. 3 (Data Structures), Ch. 4 (Sorting)
  • Elements of Programming Interviews (C#/Java/Python) β€” Aziz, Lee, Prakash β€” Ch. 5–6

🌐 Articles & References​


πŸ’» All Arrays Problems​