Skip to content
DSA Grind
All 26 sections

Blind 75 — Array Pattern Guide

Pattern guideUpdated
On this page

How to Identify an “Array” Problem

Interview Triggers

  • Input is a single 1-D integer array (often nums[])
  • Asks for an index pair / triplet / subarray that satisfies a condition (sum, product, max, etc.)
  • Words like “contiguous”, “subarray”, “pair”, “k-th”, “rotated”
  • Asks for min / max in a sequence
  • Asks to search a sorted (or rotated sorted) array

Which Sub-Pattern Does It Belong To?

If the prompt says… Use this sub-pattern Example LC
“Find two numbers that sum to target” HashMap complement 1
“Maximum profit from one buy/sell” Single pass + min tracker 121
“Are there duplicates?” HashSet 217
“Product of every element except itself” (no division) Prefix × Suffix products 238
“Maximum sum of any contiguous subarray” Kadane’s algorithm 53
“Maximum product of any contiguous subarray” Track min AND max 152
“Find min in rotated sorted array” Modified binary search 153
“Search target in rotated sorted array” Modified binary search 33
“Find triplets that sum to zero” Sort + two pointers (fix one) 15
“Maximize water/area between two lines” Two pointers from edges 11

The Decision Tree

ARRAY PROBLEM

├─ Sorted (or rotated sorted)?
│   ├─ Search / find element  → Binary Search (LC 33, 153)
│   └─ Pair/triplet sum       → Two Pointers (LC 15, 11)

├─ Need O(1) lookup of value/complement?
│   ├─ "Have I seen X?"       → HashSet (LC 217)
│   └─ "Pair that sums to T"  → HashMap value→index (LC 1)

├─ Asking about contiguous subarrays?
│   ├─ Sum (max/min)          → Kadane's (LC 53)
│   ├─ Product (max)          → Kadane variant (LC 152)
│   └─ Fixed window K         → Sliding window

├─ "Except itself" / running aggregate?
│   └─ Prefix + Suffix arrays (LC 238)

└─ Greedy / single-pass tracker?
    └─ LC 121 (min so far), LC 11 (shrink window)

Bread & Butter Problems (Must-Know)

# Problem LC # Difficulty Sub-Pattern
1 Two Sum 1 Easy HashMap complement
2 Best Time to Buy and Sell Stock 121 Easy Min tracker + greedy diff
3 Contains Duplicate 217 Easy HashSet
4 Maximum Subarray 53 Medium Kadane’s
5 Product of Array Except Self 238 Medium Prefix × Suffix products

FAANG “Aha!” Problems

# Problem LC # Difficulty Sub-Pattern
1 Maximum Product Subarray 152 Medium Track min AND max
2 Find Min in Rotated Sorted Array 153 Medium Modified binary search
3 Search in Rotated Sorted Array 33 Medium Modified binary search
4 3Sum 15 Medium Sort + two pointers
5 Container With Most Water 11 Medium Two pointers from edges

Java Implementation Tips

  • Use int[] not List<Integer> whenever the size is fixed — avoids autoboxing overhead.
  • Arrays.sort(int[]) uses Dual-Pivot Quicksort (O(n log n)) — safe for primitives.
  • Arrays.sort(Object[]) uses Timsort (stable). Use this if you need stable order.
  • For HashMap-keyed lookups, prefer Map.getOrDefault(key, 0) over containsKey + get.
  • For “max so far / min so far” trackers, init with Integer.MAX_VALUE / Integer.MIN_VALUE.

Senior Mental Trigger

“Sorted? → Binary search or two pointers. Unsorted? → HashMap. Contiguous? → Kadane or sliding window.”