A step-by-step guide to mastering arrays for DSA beginners, with 50+ curated LeetCode problems, ordered from easiest to medium difficulty, including prerequisites and concepts to know before solving each problem.
Goal: Understand arrays, indexing, traversal, and basic operations.
| # | Problem | Difficulty | Prerequisites / Concepts |
|---|---|---|---|
| 1 | Find Maximum / Minimum in Array | Easy | Array traversal, comparing elements, iteration |
| 2 | Sum of Array / Running Sum of 1D Array | Easy | Looping, cumulative sum, array indexing |
| 3 | Linear Search / Search Insert Position | Easy | Traversal, condition check, returning index |
| 4 | Contains Duplicate | Easy | Brute-force, optional HashMap for optimization |
| 5 | Maximum Product Subarray | Medium | Tracking max/min while traversing, basic DP concept |
Goal: Learn in-place changes, swapping, and two-pointer basics.
| # | Problem | Difficulty | Prerequisites / Concepts |
|---|---|---|---|
| 6 | Remove Duplicates from Sorted Array | Easy | Two pointers, in-place modification |
| 7 | Rotate Array | Easy | Array reversal, swapping, indexing |
| 8 | Move Zeroes | Easy | Two pointers, shifting elements in-place |
| 9 | Reverse String / Array | Easy | Two pointers, swapping elements |
| 10 | Replace Elements with Greatest Element on Right | Easy | Array traversal, keeping track of max value |
| 11 | Merge Sorted Array | Easy | Two pointers, merging arrays in-place |
Goal: Learn brute-force and hash-based solutions.
| # | Problem | Difficulty | Prerequisites / Concepts |
|---|---|---|---|
| 12 | Two Sum | Easy | Brute-force, HashMap for O(n) optimization |
| 13 | Single Number | Easy | XOR trick or HashMap, counting frequency |
| 14 | Intersection of Two Arrays II | Easy | HashMap for counting, array traversal |
| 15 | Running Sum of 1D Array | Easy | Prefix sum, array traversal |
| 16 | Find All Numbers Disappeared in an Array | Easy | Index mapping, in-place marking |
| 17 | Majority Element | Easy | Counting frequency, HashMap or Boyer-Moore voting algorithm |
| 18 | Find Pivot Index | Easy | Prefix sums, array traversal |
Goal: Solve problems efficiently by scanning from both ends or merging.
| # | Problem | Difficulty | Prerequisites / Concepts |
|---|---|---|---|
| 19 | Container With Most Water | Medium | Two pointers, maximizing area, left/right moves |
| 20 | Valid Palindrome | Easy | Two pointers from ends, skipping invalid characters |
| 21 | Squares of a Sorted Array | Easy | Two pointers, merging sorted arrays |
| 22 | Two Sum II - Input Array Sorted | Easy | Two pointers on sorted array |
| 23 | 3Sum | Medium | Sorting + two pointers, avoiding duplicates |
| 24 | 3Sum Closest | Medium | Sorting + two pointers, minimize difference |
| 25 | Remove Element | Easy | Two pointers, in-place deletion |
Goal: Learn efficient subarray handling techniques.
| # | Problem | Difficulty | Prerequisites / Concepts |
|---|---|---|---|
| 26 | Maximum Average Subarray I | Easy | Fixed-size sliding window, sum tracking |
| 27 | Min Size Subarray Sum | Medium | Variable-size sliding window, sum tracking |
| 28 | Longest Substring Without Repeating Characters | Medium | Sliding window + HashMap for counts |
| 29 | Subarray Sum Equals K | Medium | Prefix sum + HashMap, sum counting |
| 30 | Longest Subarray of 1’s After Deleting One Element | Medium | Sliding window, handling deletion |
| 31 | Maximum Consecutive Ones III | Medium | Sliding window with k flips |
| 32 | Permutation in String | Medium | Sliding window, frequency map, string to array mapping |
Goal: Combine sorting with pointers for intermediate problems.
| # | Problem | Difficulty | Prerequisites / Concepts |
|---|---|---|---|
| 33 | Merge Intervals | Medium | Sorting by start time, merging ranges |
| 34 | Find First and Last Position of Element | Medium | Binary search, array boundaries |
| 35 | Search in Rotated Sorted Array | Medium | Modified binary search, sorted array logic |
| 36 | 3Sum Smaller | Medium | Sorting + two pointers, counting triplets |
| 37 | Sort Colors | Medium | Dutch National Flag, two pointers |
| 38 | Intersection of Two Arrays | Easy | Sorting + two pointers, set intersection |
Goal: Combine all techniques learned so far.
| # | Problem | Difficulty | Prerequisites / Concepts |
|---|---|---|---|
| 39 | Maximum Product Subarray | Medium | Tracking max/min, handling negative numbers |
| 40 | Trapping Rain Water | Medium | Two-pointer or left/right max arrays, water trapping logic |
| 41 | Longest Consecutive Sequence | Medium | HashSet for O(n) sequence detection |
| 42 | Find Median from Data Stream | Hard | Heap / priority queue, dynamic array |
| 43 | Candy / Jump Game / Gas Station | Medium | Greedy, DP, array traversal patterns |
| 44 | Product of Array Except Self | Medium | Prefix / suffix product, no division |
| 45 | Top K Frequent Elements | Medium | HashMap + Heap, frequency counting |
| 46 | Sort an Array | Medium | Implementing QuickSort / MergeSort |
| 47 | Find All Duplicates in an Array | Medium | In-place marking, negative indexing trick |
| 48 | Set Matrix Zeroes | Medium | Matrix traversal, in-place marking |
| 49 | Rotate Image | Medium | Matrix manipulation, transpose + reverse |
| 50 | Spiral Matrix | Medium | Boundary simulation, traversal layers |
| 51 | Diagonal Traverse | Medium | Index calculation, array mapping |
This covers 50+ array problems and teaches all beginner-friendly array patterns, including: