🔢 Arrays & Strings Problems
Master array manipulation, two pointers, sliding window, and string algorithms
Two Sum - Find pair that adds to target
EasyGiven 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]
3Sum - Find triplets that sum to zero
MediumFind all unique triplets that sum to zero.
Input: [-1,0,1,2,-1,-4] → Output: [[-1,-1,2],[-1,0,1]]
Longest Substring Without Repeating Characters
MediumFind the length of the longest substring without repeating characters.
Input: "abcabcbb" → Output: 3 ("abc")
Container With Most Water - Two Pointers
MediumFind two lines that together with the x-axis form a container with most water.
Maximum Subarray - Kadane's Algorithm
MediumFind the contiguous subarray with the largest sum.
Input: [-2,1,-3,4,-1,2,1,-5,4] → Output: 6 ([4,-1,2,1])
Merge Intervals - Combine overlapping intervals
MediumMerge all overlapping intervals.
Input: [[1,3],[2,6],[8,10],[15,18]] → Output: [[1,6],[8,10],[15,18]]
Product of Array Except Self
MediumReturn 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]
Trapping Rain Water
HardGiven 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
Minimum Window Substring
HardFind 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