Array LeetCode Problems: All 1,569, With Python Solutions
Every problem in this library that LeetCode tags Array — 1,569 in total, 1,332 of them with a complete Python solution, a worked example and the time and space complexity of the approach.
- 1,569 problems
- 330 Easy
- 862 Medium
- 377 Hard
Array problems by difficulty
Showing the first 200 of 1,569 problems. Problems with a complete Python solution are listed first, then by ascending problem number.
Easy (31)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 1 | Two Sum | Easy | Array, Hash Table |
| 14 | Longest Common Prefix | Easy | Trie, Array, String |
| 26 | Remove Duplicates from Sorted Array | Easy | Array, Two Pointers |
| 27 | Remove Element | Easy | Array, Two Pointers |
| 35 | Search Insert Position | Easy | Array, Binary Search |
| 66 | Plus One | Easy | Array, Math |
| 88 | Merge Sorted Array | Easy | Array, Two Pointers, Sorting |
| 108 | Convert Sorted Array to Binary Search Tree | Easy | Tree, Binary Search Tree, Array +2 |
| 118 | Pascal's Triangle | Easy | Array, Dynamic Programming |
| 119 | Pascal's Triangle II | Easy | Array, Dynamic Programming |
| 121 | Best Time to Buy and Sell Stock | Easy | Array, Dynamic Programming |
| 136 | Single Number | Easy | Bit Manipulation, Array |
| 169 | Majority Element | Easy | Array, Hash Table, Divide and Conquer +2 |
| 217 | Contains Duplicate | Easy | Array, Hash Table, Sorting |
| 219 | Contains Duplicate II | Easy | Array, Hash Table, Sliding Window |
| 228 | Summary Ranges | Easy | Array |
| 268 | Missing Number | Easy | Bit Manipulation, Array, Hash Table +3 |
| 283 | Move Zeroes | Easy | Array, Two Pointers |
| 303 | Range Sum Query - Immutable | Easy | Design, Array, Prefix Sum |
| 349 | Intersection of Two Arrays | Easy | Array, Hash Table, Two Pointers +2 |
| 350 | Intersection of Two Arrays II | Easy | Array, Hash Table, Two Pointers +2 |
| 414 | Third Maximum Number | Easy | Array, Sorting |
| 448 | Find All Numbers Disappeared in an Array | Easy | Array, Hash Table |
| 455 | Assign Cookies | Easy | Greedy, Array, Two Pointers +1 |
| 463 | Island Perimeter | Easy | Depth-First Search, Breadth-First Search, Array +1 |
| 485 | Max Consecutive Ones | Easy | Array |
| 495 | Teemo Attacking | Easy | Array, Simulation |
| 496 | Next Greater Element I | Easy | Stack, Array, Hash Table +1 |
| 500 | Keyboard Row | Easy | Array, Hash Table, String |
| 506 | Relative Ranks | Easy | Array, Sorting, Heap (Priority Queue) |
| 561 | Array Partition | Easy | Greedy, Array, Counting Sort +1 |
Medium (128)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 11 | Container With Most Water | Medium | Greedy, Array, Two Pointers |
| 15 | 3Sum | Medium | Array, Two Pointers, Sorting |
| 16 | 3Sum Closest | Medium | Array, Two Pointers, Sorting |
| 18 | 4Sum | Medium | Array, Two Pointers, Sorting |
| 31 | Next Permutation | Medium | Array, Two Pointers |
| 33 | Search in Rotated Sorted Array | Medium | Array, Binary Search |
| 34 | Find First and Last Position of Element in Sorted Array | Medium | Array, Binary Search |
| 36 | Valid Sudoku | Medium | Array, Hash Table, Matrix |
| 39 | Combination Sum | Medium | Array, Backtracking |
| 40 | Combination Sum II | Medium | Array, Backtracking |
| 45 | Jump Game II | Medium | Greedy, Array, Dynamic Programming |
| 46 | Permutations | Medium | Array, Backtracking |
| 47 | Permutations II | Medium | Array, Backtracking, Sorting |
| 48 | Rotate Image | Medium | Array, Math, Matrix |
| 49 | Group Anagrams | Medium | Array, Hash Table, String +1 |
| 53 | Maximum Subarray | Medium | Array, Divide and Conquer, Dynamic Programming |
| 54 | Spiral Matrix | Medium | Array, Matrix, Simulation |
| 55 | Jump Game | Medium | Greedy, Array, Dynamic Programming |
| 56 | Merge Intervals | Medium | Array, Sorting |
| 57 | Insert Interval | Medium | Array |
| 59 | Spiral Matrix II | Medium | Array, Matrix, Simulation |
| 63 | Unique Paths II | Medium | Array, Dynamic Programming, Matrix |
| 64 | Minimum Path Sum | Medium | Array, Dynamic Programming, Matrix |
| 73 | Set Matrix Zeroes | Medium | Array, Hash Table, Matrix |
| 74 | Search a 2D Matrix | Medium | Array, Binary Search, Matrix |
| 75 | Sort Colors | Medium | Array, Two Pointers, Sorting |
| 78 | Subsets | Medium | Bit Manipulation, Array, Backtracking |
| 79 | Word Search | Medium | Depth-First Search, Array, String +2 |
| 80 | Remove Duplicates from Sorted Array II | Medium | Array, Two Pointers |
| 81 | Search in Rotated Sorted Array II | Medium | Array, Binary Search |
| 90 | Subsets II | Medium | Bit Manipulation, Array, Backtracking |
| 105 | Construct Binary Tree from Preorder and Inorder Traversal | Medium | Tree, Array, Hash Table +2 |
| 106 | Construct Binary Tree from Inorder and Postorder Traversal | Medium | Tree, Array, Hash Table +2 |
| 120 | Triangle | Medium | Array, Dynamic Programming |
| 122 | Best Time to Buy and Sell Stock II | Medium | Greedy, Array, Dynamic Programming |
| 128 | Longest Consecutive Sequence | Medium | Union Find, Array, Hash Table |
| 130 | Surrounded Regions | Medium | Depth-First Search, Breadth-First Search, Union Find +2 |
| 134 | Gas Station | Medium | Greedy, Array |
| 137 | Single Number II | Medium | Bit Manipulation, Array |
| 139 | Word Break | Medium | Trie, Memoization, Array +3 |
| 150 | Evaluate Reverse Polish Notation | Medium | Stack, Array, Math |
| 152 | Maximum Product Subarray | Medium | Array, Dynamic Programming |
| 153 | Find Minimum in Rotated Sorted Array | Medium | Array, Binary Search |
| 162 | Find Peak Element | Medium | Array, Binary Search |
| 164 | Maximum Gap | Medium | Array, Bucket Sort, Radix Sort +1 |
| 167 | Two Sum II - Input Array Is Sorted | Medium | Array, Two Pointers, Binary Search |
| 179 | Largest Number | Medium | Greedy, Array, String +1 |
| 189 | Rotate Array | Medium | Array, Math, Two Pointers |
| 198 | House Robber | Medium | Array, Dynamic Programming |
| 200 | Number of Islands | Medium | Depth-First Search, Breadth-First Search, Union Find +2 |
| 204 | Count Primes | Medium | Array, Math, Enumeration +1 |
| 209 | Minimum Size Subarray Sum | Medium | Array, Binary Search, Prefix Sum +1 |
| 213 | House Robber II | Medium | Array, Dynamic Programming |
| 215 | Kth Largest Element in an Array | Medium | Array, Divide and Conquer, Quickselect +2 |
| 216 | Combination Sum III | Medium | Array, Backtracking |
| 221 | Maximal Square | Medium | Array, Dynamic Programming, Matrix |
| 229 | Majority Element II | Medium | Array, Hash Table, Counting +1 |
| 238 | Product of Array Except Self | Medium | Array, Prefix Sum |
| 240 | Search a 2D Matrix II | Medium | Array, Binary Search, Divide and Conquer +1 |
| 260 | Single Number III | Medium | Bit Manipulation, Array |
| 274 | H-Index | Medium | Array, Counting Sort, Sorting |
| 275 | H-Index II | Medium | Array, Binary Search |
| 284 | Peeking Iterator | Medium | Design, Array, Iterator |
| 287 | Find the Duplicate Number | Medium | Bit Manipulation, Array, Two Pointers +1 |
| 289 | Game of Life | Medium | Array, Matrix, Simulation |
| 300 | Longest Increasing Subsequence | Medium | Array, Binary Search, Dynamic Programming |
| 304 | Range Sum Query 2D - Immutable | Medium | Design, Array, Matrix +1 |
| 307 | Range Sum Query - Mutable | Medium | Design, Binary Indexed Tree, Segment Tree +2 |
| 309 | Best Time to Buy and Sell Stock with Cooldown | Medium | Array, Dynamic Programming |
| 313 | Super Ugly Number | Medium | Array, Math, Dynamic Programming |
| 318 | Maximum Product of Word Lengths | Medium | Bit Manipulation, Array, String |
| 322 | Coin Change | Medium | Breadth-First Search, Array, Dynamic Programming |
| 324 | Wiggle Sort II | Medium | Greedy, Array, Divide and Conquer +2 |
| 334 | Increasing Triplet Subsequence | Medium | Greedy, Array |
| 347 | Top K Frequent Elements | Medium | Array, Hash Table, Divide and Conquer +5 |
| 368 | Largest Divisible Subset | Medium | Array, Math, Dynamic Programming +1 |
| 373 | Find K Pairs with Smallest Sums | Medium | Array, Heap (Priority Queue) |
| 376 | Wiggle Subsequence | Medium | Greedy, Array, Dynamic Programming |
| 377 | Combination Sum IV | Medium | Array, Dynamic Programming |
| 378 | Kth Smallest Element in a Sorted Matrix | Medium | Array, Binary Search, Matrix +2 |
| 380 | Insert Delete GetRandom O(1) | Medium | Design, Array, Hash Table +2 |
| 384 | Shuffle an Array | Medium | Design, Array, Math +1 |
| 393 | UTF-8 Validation | Medium | Bit Manipulation, Array |
| 396 | Rotate Function | Medium | Array, Math, Dynamic Programming |
| 399 | Evaluate Division | Medium | Depth-First Search, Breadth-First Search, Union Find +4 |
| 406 | Queue Reconstruction by Height | Medium | Binary Indexed Tree, Segment Tree, Array +1 |
| 413 | Arithmetic Slices | Medium | Array, Dynamic Programming, Sliding Window |
| 416 | Partition Equal Subset Sum | Medium | Array, Dynamic Programming |
| 417 | Pacific Atlantic Water Flow | Medium | Depth-First Search, Breadth-First Search, Array +1 |
| 419 | Battleships in a Board | Medium | Depth-First Search, Array, Matrix |
| 421 | Maximum XOR of Two Numbers in an Array | Medium | Bit Manipulation, Trie, Array +1 |
| 427 | Construct Quad Tree | Medium | Tree, Array, Divide and Conquer +1 |
| 435 | Non-overlapping Intervals | Medium | Greedy, Array, Dynamic Programming +1 |
| 436 | Find Right Interval | Medium | Array, Binary Search, Sorting |
| 442 | Find All Duplicates in an Array | Medium | Array, Hash Table, Sorting |
| 447 | Number of Boomerangs | Medium | Array, Hash Table, Math |
| 452 | Minimum Number of Arrows to Burst Balloons | Medium | Greedy, Array, Sorting |
| 453 | Minimum Moves to Equal Array Elements | Medium | Array, Math |
| 454 | 4Sum II | Medium | Array, Hash Table |
| 456 | 132 Pattern | Medium | Stack, Array, Binary Search +2 |
| 457 | Circular Array Loop | Medium | Array, Hash Table, Two Pointers |
| 462 | Minimum Moves to Equal Array Elements II | Medium | Array, Math, Sorting |
| 473 | Matchsticks to Square | Medium | Bit Manipulation, Array, Dynamic Programming +2 |
| 474 | Ones and Zeroes | Medium | Array, String, Dynamic Programming |
| 475 | Heaters | Medium | Array, Two Pointers, Binary Search +1 |
| 477 | Total Hamming Distance | Medium | Bit Manipulation, Array, Math |
| 486 | Predict the Winner | Medium | Recursion, Array, Math +2 |
| 491 | Non-decreasing Subsequences | Medium | Bit Manipulation, Array, Hash Table +1 |
| 494 | Target Sum | Medium | Array, Dynamic Programming, Backtracking |
| 497 | Random Point in Non-overlapping Rectangles | Medium | Reservoir Sampling, Array, Math +4 |
| 498 | Diagonal Traverse | Medium | Array, Matrix, Simulation |
| 503 | Next Greater Element II | Medium | Stack, Array, Monotonic Stack |
| 518 | Coin Change II | Medium | Array, Dynamic Programming |
| 522 | Longest Uncommon Subsequence II | Medium | Array, Hash Table, Two Pointers +2 |
| 523 | Continuous Subarray Sum | Medium | Array, Hash Table, Math +1 |
| 524 | Longest Word in Dictionary through Deleting | Medium | Array, Two Pointers, String +1 |
| 525 | Contiguous Array | Medium | Array, Hash Table, Prefix Sum |
| 526 | Beautiful Arrangement | Medium | Bit Manipulation, Array, Dynamic Programming +2 |
| 528 | Random Pick with Weight | Medium | Array, Math, Binary Search +2 |
| 529 | Minesweeper | Medium | Depth-First Search, Breadth-First Search, Array +1 |
| 532 | K-diff Pairs in an Array | Medium | Array, Hash Table, Two Pointers +2 |
| 539 | Minimum Time Difference | Medium | Array, Math, String +1 |
| 540 | Single Element in a Sorted Array | Medium | Array, Binary Search |
| 542 | 01 Matrix | Medium | Breadth-First Search, Array, Dynamic Programming +1 |
| 553 | Optimal Division | Medium | Array, Math, Dynamic Programming |
| 554 | Brick Wall | Medium | Array, Hash Table |
| 560 | Subarray Sum Equals K | Medium | Array, Hash Table, Prefix Sum |
| 565 | Array Nesting | Medium | Depth-First Search, Array |
Hard (41)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 4 | Median of Two Sorted Arrays | Hard | Array, Binary Search, Divide and Conquer |
| 37 | Sudoku Solver | Hard | Array, Hash Table, Backtracking +1 |
| 41 | First Missing Positive | Hard | Array, Hash Table |
| 42 | Trapping Rain Water | Hard | Stack, Array, Two Pointers +2 |
| 51 | N-Queens | Hard | Array, Backtracking |
| 68 | Text Justification | Hard | Array, String, Simulation |
| 84 | Largest Rectangle in Histogram | Hard | Stack, Array, Monotonic Stack |
| 85 | Maximal Rectangle | Hard | Stack, Array, Dynamic Programming +2 |
| 123 | Best Time to Buy and Sell Stock III | Hard | Array, Dynamic Programming |
| 135 | Candy | Hard | Greedy, Array |
| 140 | Word Break II | Hard | Trie, Memoization, Array +4 |
| 149 | Max Points on a Line | Hard | Geometry, Array, Hash Table +1 |
| 154 | Find Minimum in Rotated Sorted Array II | Hard | Array, Binary Search |
| 174 | Dungeon Game | Hard | Array, Dynamic Programming, Matrix |
| 188 | Best Time to Buy and Sell Stock IV | Hard | Array, Dynamic Programming |
| 212 | Word Search II | Hard | Trie, Array, String +2 |
| 218 | The Skyline Problem | Hard | Binary Indexed Tree, Segment Tree, Array +5 |
| 220 | Contains Duplicate III | Hard | Array, Bucket Sort, Ordered Set +2 |
| 239 | Sliding Window Maximum | Hard | Queue, Array, Sliding Window +2 |
| 312 | Burst Balloons | Hard | Array, Dynamic Programming |
| 315 | Count of Smaller Numbers After Self | Hard | Binary Indexed Tree, Segment Tree, Array +4 |
| 321 | Create Maximum Number | Hard | Stack, Greedy, Array +2 |
| 327 | Count of Range Sum | Hard | Binary Indexed Tree, Segment Tree, Array +4 |
| 329 | Longest Increasing Path in a Matrix | Hard | Depth-First Search, Breadth-First Search, Graph +5 |
| 330 | Patching Array | Hard | Greedy, Array |
| 335 | Self Crossing | Hard | Geometry, Array, Math |
| 336 | Palindrome Pairs | Hard | Trie, Array, Hash Table +1 |
| 354 | Russian Doll Envelopes | Hard | Array, Binary Search, Dynamic Programming +1 |
| 363 | Max Sum of Rectangle No Larger Than K | Hard | Array, Binary Search, Matrix +2 |
| 381 | Insert Delete GetRandom O(1) - Duplicates allowed | Hard | Design, Array, Hash Table +2 |
| 391 | Perfect Rectangle | Hard | Geometry, Array, Hash Table +2 |
| 403 | Frog Jump | Hard | Array, Dynamic Programming |
| 407 | Trapping Rain Water II | Hard | Breadth-First Search, Array, Matrix +1 |
| 410 | Split Array Largest Sum | Hard | Greedy, Array, Binary Search +2 |
| 446 | Arithmetic Slices II - Subsequence | Hard | Array, Dynamic Programming |
| 472 | Concatenated Words | Hard | Depth-First Search, Trie, Array +3 |
| 480 | Sliding Window Median | Hard | Array, Hash Table, Sliding Window +1 |
| 493 | Reverse Pairs | Hard | Binary Indexed Tree, Segment Tree, Array +4 |
| 502 | IPO | Hard | Greedy, Array, Sorting +1 |
| 517 | Super Washing Machines | Hard | Greedy, Array |
| 546 | Remove Boxes | Hard | Memoization, Array, Dynamic Programming |
Keep exploring
All LeetCode topicsEvery tag with a page of its own, with the number of problems behind each.LeetCode patternsThe techniques themselves, with a Python template and complexity for each.Curated study listsBlind 75, NeetCode 150 and three more, grouped by pattern.Easy problemsStart here when the data structure is new rather than the problem.
Other topics
- String672
- Hash Table588
- Math485
- Dynamic Programming481
- Sorting392
- Greedy346
- Depth-First Search289
- Binary Search253
- Database249
- Tree225
- Breadth-First Search223
- Matrix216
- Two Pointers201
- Bit Manipulation194
- Binary Tree174
- Heap (Priority Queue)163
- Prefix Sum157
- Stack157
- Simulation144
- Graph138
- Counting126
- Design122
- Sliding Window116
- Backtracking105
When the Array problem arrives live
Stealth Interview is a desktop app for macOS and Windows. It reads the coding problem off your screen, returns a working solution with a step-by-step explanation and its time and space complexity, and transcribes what the interviewer is saying — while staying invisible to screen sharing.