🔢 Arrays & Strings Problems
Master array manipulation, two pointers, sliding window, and string algorithms
Given an array of integers and a target, return indices of two numbers that add up to target.
Input: nums = [2,7,11,15], target = 9 → Output: [0,1]
Find all unique triplets that sum to zero.
Input: [-1,0,1,2,-1,-4] → Output: [[-1,-1,2],[-1,0,1]]
Find the length of the longest substring without repeating characters.
Input: "abcabcbb" → Output: 3 ("abc")
Find two lines that together with the x-axis form a container with most water.
Find the contiguous subarray with the largest sum.
Input: [-2,1,-3,4,-1,2,1,-5,4] → Output: 6 ([4,-1,2,1])
Merge all overlapping intervals.
Input: [[1,3],[2,6],[8,10],[15,18]] → Output: [[1,6],[8,10],[15,18]]
Return an array where each element is the product of all elements except itself. No division allowed.
Input: [1,2,3,4] → Output: [24,12,8,6]
Given elevation map, compute how much water it can trap after raining.
Input: [0,1,0,2,1,0,1,3,2,1,2,1] → Output: 6
Find the minimum window in s which contains all characters of t.
Input: s = "ADOBECODEBANC", t = "ABC" → Output: "BANC"
Arrays & Strings Patterns
- ✓ Two Pointers: Use for sorted arrays, palindromes, pair finding
- ✓ Sliding Window: Fixed or variable window for substring/subarray problems
- ✓ Hash Map: O(1) lookup for frequency counting, two sum variants
- ✓ Prefix Sum: Range sum queries, subarray sum problems
- ✓ Sorting: Often enables two-pointer or binary search approaches
- ✓ In-place operations: Use swapping to avoid extra space