Arrays Coding Problems: 667 Questions with Solutions
667 arrays coding problems — 247 easy · 329 medium · 91 hard — with solutions in 13 languages. Plus a step-by-step walkthrough and a 8-day plan.
- Problems: 667
- By difficulty: 247 easy · 329 medium · 91 hard
- Languages: JavaScript, TypeScript, Python, Java, C++, C, C#, Go, Kotlin, Swift, Rust, PHP and Ruby
- Cost: Free on every plan; sign in to run and submit
The array is the first data structure every other one is built on: a block of values addressed by index in constant time. Array problems practise the moves that recur everywhere else — scanning once, keeping a running best, working from both ends, sorting first to make a hard question easy, and reasoning about indices without going off either end. Most of the catalogue touches an array somewhere; the problems here are the ones where the array itself is the point.
How arrays works, step by step
prices = [7, 1, 5, 3, 6, 4]- Selling on day i earns prices[i] minus the cheapest price before it. So one pass only has to remember two numbers: the cheapest price so far and the best profit so far.
- Day 0 costs 7. Nothing came before it, so 7 is the cheapest price so far and there is nothing to sell yet.
- Day 1 costs 1, below the old cheapest 7, so day 1 becomes the day to buy. Selling on the day you buy earns nothing, and the best profit stays 0.
- Day 2 costs 5. Buying at the cheapest earlier price (1, day 1) and selling today earns 5 − 1 = 4, so best = 4. Earlier days other than the cheapest can be forgotten: none of them is a better day to buy.
- Day 3 costs 3: selling today would earn 2, less than the best 4, and 3 is not below 1, so neither number changes.
- Day 4 costs 6. Buying at the cheapest earlier price (1, day 1) and selling today earns 6 − 1 = 5, so best = 5.
- Day 5 costs 4: selling today would earn 3, less than the best 5, and 4 is not below 1, so neither number changes.
- The best trade is to buy on day 1 at 1 and sell on day 4 at 6, a profit of 5. Each day was looked at once with two numbers kept, so it is O(n) time and O(1) space.
Arrays study plan
14 of the 667 Arrays problems (4 easy, 7 medium and 3 hard) over 8 days, about 8 h 10 min in all — the pattern first, then easiest to hardest. After that, the other 653 in the full list below are practice at your own pace. Then move on to Strings.
Day 1
Learn the pattern: read the essentials and step through the walkthrough above, then solve these 3.
Day 2
Medium problems: the same pattern with one twist each. Name the twist before you code.
- Richest Customer Wealth Easy
- Maximum Subarray Medium
Day 3
More mediums. Before coding each one, write down what state the pattern keeps and when it changes.
- Product of Array Except Self Medium
- Longest Consecutive Sequence Medium
Day 4
More mediums. Before coding each one, write down what state the pattern keeps and when it changes.
Day 5
More mediums. Before coding each one, write down what state the pattern keeps and when it changes.
- 3Sum Medium
- Container With Most Water Medium
Day 6
Hard problems: the pattern combined with a second idea. Give each a full attempt before reading the editorial.
- Trapping Rain Water Hard
Day 7
Another hard one. If it beats you after a real attempt, read the editorial, then solve it again tomorrow from memory.
Day 8
Another hard one. If it beats you after a real attempt, read the editorial, then solve it again tomorrow from memory.
Arrays: the essentials
When to reach for it
The input is a list of numbers and the question is about positions, order or aggregates: the best pair of days, an element's neighbours, a value's frequency, a rearrangement that must happen in place. With n up to 10⁵, comparing every pair is about 5 × 10⁹ steps, so the answer must come from one or two passes. "In place" or "O(1) extra space" means the array itself must hold the working state.
The pattern
Most array solutions are a single pass that carries a little state: the smallest value so far, a write index, a running total. Ask what you need to know about everything before index i to answer for i, keep exactly that, and update it in constant time. When the answer at i depends on both sides, a pass from the left and a pass from the right usually suffice — the idea behind Prefix Sum.
def max_profit(prices):
best, low = 0, float("inf")
for p in prices:
low = min(low, p) # cheapest day so far
best = max(best, p - low) # sell today
return best
Cost
One pass is O(n) time. The carried state is O(1) space, or O(n) when you keep a prefix or suffix array. Sorting first costs O(n log n) and usually reorders the caller's array.
Common mistakes
- Reading
nums[i + 1]ornums[i - 1]without guarding the ends. - Removing elements while looping by index, which skips the element that slides into the gap.
- Starting a running maximum at 0 when every value can be negative.
- Returning a new array when the problem wants the input modified and a length returned.
Start with
- Best Time to Buy and Sell Stock: one pass with a running minimum.
- Move Zeroes: a write index, in place.
- Product of Array Except Self: a left pass and a right pass.
All arrays problems
Easy (247)
- Special Array I
- Type of Triangle Math, Sorting
- Find the Losers of the Circular Game Hash Table, Simulation
- Form Smallest Number From Two Digit Arrays Hash Table, Enumeration
- Delete Greatest Value in Each Row Matrix, Sorting, Simulation
- The Employee That Worked on the Longest Task
- Most Frequent Even Element Hash Table, Counting
- Number of Strings That Appear as Substrings in Word String
- Number of Senior Citizens String
- Find Words Containing Character String
- Count Prefixes of a Given String String
- Count the Number of Incremovable Subarrays I Two Pointers, Enumeration
- Modify the Matrix Matrix
- Find the Power of K-Size Subarrays I Sliding Window
- Find the XOR of Numbers Which Appear Twice Hash Table, Bit Manipulation
- Apple Redistribution into Boxes Greedy, Sorting
- Number of Beautiful Pairs Hash Table, Math, Counting
- Check if Array is Good Hash Table, Sorting
- Neither Minimum nor Maximum Sorting
- Alternating Groups I Sliding Window
- Distribute Elements Into Two Arrays I Simulation
- Minimum Sum of Mountain Triplets I Prefix Sum
- Find the Integer Added to Array I Math
- Minimum Operations to Exceed Threshold Value I
- Kids With the Greatest Number of Candies
- Separate the Digits in an Array Simulation
- Minimum Time Visiting All Points Math, Geometry
- Split the Array Hash Table, Counting
- Find Champion I Matrix, Graph
- Prime In Diagonal Math, Matrix, Number Theory
- Matrix Similarity After Cyclic Shifts Matrix, Simulation
- Determine the Winner of a Bowling Game Simulation
- Best Poker Hand Hash Table, Counting, Greedy
- Maximum Height of a Triangle Greedy, Enumeration, Simulation
- Minimum Amount of Time to Fill Cups Greedy, Math, Heap
- Take Gifts From the Richest Pile Heap, Simulation, Greedy
- Kth Missing Positive Number Binary Search
- Find Smallest Letter Greater Than Target Binary Search
- Count Subarrays of Length Three With a Condition Sliding Window
- Defuse the Bomb Sliding Window, Simulation
- Maximum Sum Subarray of Size K Sliding Window
- Shortest Word Distance String, Two Pointers
- Find Indices With Index and Value Difference I Two Pointers
- Pair With Given Difference Two Pointers, Sorting
- Count Number of Pairs With Absolute Difference K Hash Table, Counting
- Shortest Distance to Target String in a Circular Array String, Two Pointers
- Intersection of Multiple Arrays Hash Table, Counting
- DI String Match Two Pointers, Greedy, String
- Two Sum Less Than K Two Pointers, Sorting
- Find the Distance Value Between Two Arrays Two Pointers, Binary Search
- Merge Two 2D Arrays by Summing Values Two Pointers
- Shortest Subarray With OR at Least K I Bit Manipulation, Sliding Window
- Maximum Strong Pair XOR I Bit Manipulation, Trie
- Find the K-or of an Array Bit Manipulation
- Find the Maximum Divisibility Score Math, Counting
- Sum of Squares of Special Elements Math, Number Theory
- Number of Distinct Averages Hash Table, Two Pointers, Sorting
- Number of Lines To Write String String, Simulation
- Counting Elements Hash Table, Counting
- Largest Unique Number Hash Table, Sorting
- Maximum Number of Words Found in Sentences String
- Count the Number of Vowel Strings in Range String
- Check If String Is a Prefix of Array String
- Minimum Number Game Sorting, Simulation
- Count Pairs With Given Sum Hash Table
- Maximum Difference Between Adjacent Elements in a Circular Array
- Sort the People Sorting, Hash Table
- Left Rotate an Array by D Places Two Pointers
- Common Elements in Three Sorted Arrays Two Pointers
- Find Transition Point Binary Search
- Convert Array Into Zig-Zag Fashion Greedy
- Wave Array Sorting
- Minimum Operations to Collect Elements Hash Table, Simulation
- Maximum Sum With Exactly K Elements Greedy
- Find the Array Concatenation Value Two Pointers, Simulation
- Sum of Values at Indices With K Set Bits Bit Manipulation
- Find the Distinct Difference Array Hash Table, Prefix Sum
- Maximum Ascending Subarray Sum
- Find the Peaks Enumeration
- The Two Sneaky Numbers of Digitville Hash Table
- Find the Difference of Two Arrays Hash Table
- Largest Positive Integer That Exists With Its Negative Hash Table, Two Pointers
- Maximum Number of Pairs in Array Hash Table, Counting
- Rank Transform of an Array Hash Table, Sorting
- N-Repeated Element in Size 2N Array Hash Table
- Find Common Characters String, Hash Table
- Keyboard Row String, Hash Table
- Minimum Index Sum of Two Lists String, Hash Table
- Count Elements With Maximum Frequency Hash Table, Counting
- Sum of Unique Elements Hash Table, Counting
- Unique Number of Occurrences Hash Table
- Points That Intersect With Cars Prefix Sum
- Minimum Right Shifts to Sort the Array
- Count Tested Devices After Test Operations Simulation, Counting
- Ant on the Boundary Prefix Sum, Simulation
- Number of Employees Who Met the Target
- Check If It Is a Straight Line Math, Geometry
- Add to Array-Form of Integer Math
- Split Strings by Separator String
- Maximum Value of a String in an Array String
- Odd String Difference String, Hash Table
- Find First Palindromic String in the Array String, Two Pointers
- Count Common Words With One Occurrence String, Hash Table
- Redistribute Characters to Make All Strings Equal String, Counting
- Verifying an Alien Dictionary String, Hash Table
- Unique Morse Code Words String, Hash Table
- Union of Two Sorted Arrays Two Pointers
- Chocolate Distribution Problem Sorting, Sliding Window
- Divide Array Into Equal Pairs Hash Table, Bit Manipulation
- Count Equal and Divisible Pairs in an Array
- Maximum Difference Between Increasing Elements
- Maximum Population Year Prefix Sum, Counting
- Minimum Distance to the Target Element
- Minimum Operations to Make the Array Increasing Greedy
- Sign of the Product of an Array Math
- Number of Students Doing Homework at a Given Time
- Check If All 1's Are at Least Length K Places Away
- Teemo Attacking Simulation
- Minimum Subsequence in Non-Increasing Order Greedy, Sorting
- Find Lucky Integer in an Array Hash Table, Counting
- Minimum Value to Get Positive Step by Step Sum Prefix Sum
- Find N Unique Integers Sum up to Zero Math
- Replace Elements with Greatest Element on Right Side
- Distribute Candies to People Math, Simulation
- Duplicate Zeros Two Pointers
- Partition Array Into Three Parts With Equal Sum Greedy, Prefix Sum
- X of a Kind in a Deck of Cards Math, Number Theory
- Fair Candy Swap Hash Table
- Monotonic Array
- Equilibrium Point Prefix Sum
- Leaders in an Array
- Second Largest Element
- Sum of All Subset XOR Totals Math, Backtracking, Bit Manipulation
- Count the Number of Consistent Strings Hash Table, String, Bit Manipulation
- Decode XORed Array Bit Manipulation
- Number of Students Unable to Eat Lunch Stack, Queue, Simulation
- Time Needed to Buy Tickets Queue, Simulation
- Final Prices With a Special Discount in a Shop Stack, Monotonic Stack
- Crawler Log Folder String, Stack
- Baseball Game String, Stack, Simulation
- Sort Even and Odd Indices Independently Sorting
- Sort Integers by The Number of 1 Bits Bit Manipulation, Sorting, Counting
- Maximum Product of Three Numbers Math, Sorting
- Minimum Absolute Difference Sorting
- Sort Array by Increasing Frequency Hash Table, Sorting
- Smallest Range I Math
- Largest Perimeter Triangle Math, Greedy, Sorting
- Sort Array By Parity II Two Pointers, Sorting
- Minimum Cost to Move Chips to The Same Position Math, Greedy
- Maximum Units on a Truck Greedy, Sorting
- Assign Cookies Two Pointers, Greedy, Sorting
- Special Positions in a Binary Matrix Matrix
- Projection Area of 3D Shapes Math, Geometry, Matrix
- Matrix Cells in Distance Order Math, Matrix, Sorting
- Find Winner on a Tic Tac Toe Game Hash Table, Matrix, Simulation
- Convert 1D Array Into 2D Array Matrix, Simulation
- Cells with Odd Values in a Matrix Math, Simulation
- Largest Local Values in a Matrix Matrix
- Row With Maximum Ones Matrix
- Check if Matrix Is X-Matrix Matrix
- Determine Whether Matrix Can Be Obtained By Rotation Matrix
- Pascal's Triangle II Dynamic Programming
- Number of Equivalent Domino Pairs Hash Table, Counting
- The K Weakest Rows in a Matrix Binary Search, Sorting, Heap
- Shift 2D Grid Matrix, Simulation
- Lucky Numbers in a Matrix Matrix
- Count Negative Numbers in a Sorted Matrix Binary Search, Matrix
- Image Smoother Matrix
- Flipping an Image Two Pointers, Matrix, Simulation
- Reshape the Matrix Matrix, Simulation
- Toeplitz Matrix Matrix
- Maximum Count of Positive Integer and Negative Integer Binary Search, Counting
- Number of Arithmetic Triplets Hash Table, Two Pointers, Enumeration
- Difference Between Element Sum and Digit Sum of an Array Math
- Left and Right Sum Differences Prefix Sum
- Apply Operations to an Array Two Pointers, Simulation
- Minimum Common Value Hash Table, Two Pointers, Binary Search
- Count Pairs Whose Sum is Less than Target Two Pointers, Binary Search, Sorting
- Minimum Number of Moves to Seat Everyone Greedy, Sorting, Counting Sort
- Maximum Product Difference Between Two Pairs Greedy, Sorting
- Special Array With X Elements Greater Than or Equal X Binary Search, Sorting, Counting Sort
- Count Good Triplets Enumeration
- Three Consecutive Odds
- Maximum Product of Two Elements in an Array Sorting, Heap
- Array Partition Greedy, Sorting, Counting Sort
- Minimum Difference Between Highest and Lowest of K Scores Sliding Window, Sorting
- Check If N and Its Double Exist Hash Table, Two Pointers, Sorting
- Can Make Arithmetic Progression From Sequence Sorting
- Shortest Distance to a Character Two Pointers, String
- Remove Element Two Pointers
- Check If Two String Arrays Are Equivalent String
- Unique Email Addresses Hash Table, String
- Truncate Sentence String
- Shuffle String String
- Relative Sort Array Hash Table, Sorting, Counting Sort
- Height Checker Sorting, Counting Sort
- Sort Array By Parity Two Pointers, Sorting
- Distribute Candies Hash Table, Greedy
- Longest Harmonious Subsequence Hash Table, Sorting, Sliding Window
- Degree of an Array Hash Table
- Can Place Flowers Greedy
- Third Maximum Number Sorting
- Max Consecutive Ones
- Sum of All Odd Length Subarrays Math, Prefix Sum
- Find the Highest Altitude Prefix Sum
- Create Target Array in the Given Order Simulation
- Decompress Run-Length Encoded List Simulation
- Concatenation of Array Simulation
- Build Array from Permutation Simulation
- Shuffle the Array
- Number of Good Pairs Hash Table, Math, Counting
- How Many Numbers Are Smaller Than the Current Number Hash Table, Counting Sort
- Running Sum of 1d Array Prefix Sum
- Find Pivot Index Prefix Sum
- Set Mismatch Hash Table, Bit Manipulation, Sorting
- Intersection of Two Arrays II Hash Table, Two Pointers, Sorting
- Intersection of Two Arrays Hash Table, Two Pointers, Sorting
- Contains Duplicate II Hash Table, Sliding Window
- Find Numbers with Even Number of Digits Math
- Find Greatest Common Divisor of Array Math, Number Theory
- Plus One Math
- Summary Ranges
- Meeting Rooms Sorting, Intervals
- Island Perimeter Matrix
- Flood Fill Matrix, Depth-First Search, Breadth-First Search
- Richest Customer Wealth Matrix
- Matrix Diagonal Sum Matrix
- Pascal's Triangle Dynamic Programming
- Transpose Matrix Matrix, Simulation
- Relative Ranks Heap, Sorting
- Last Stone Weight Heap
- Min Cost Climbing Stairs Dynamic Programming
- Lemonade Change Greedy
- Next Greater Element I Stack, Hash Table
- Search Insert Position Binary Search
- Squares of a Sorted Array Two Pointers, Sorting
- Merge Sorted Array Two Pointers, Sorting
- Single Number Bit Manipulation
- Find All Numbers Disappeared in an Array Hash Table
- Missing Number Math, Bit Manipulation
- Majority Element Hash Table, Divide and Conquer
- Remove Duplicates from Sorted Array Two Pointers
- Move Zeroes Two Pointers
- Best Time to Buy and Sell Stock Dynamic Programming
- Contains Duplicate Hash Table, Sorting
- Binary Search Binary Search
- Two Sum Hash Table
Medium (329)
- Minimum Number of Increments on Subarrays to Form a Target Array Greedy, Dynamic Programming, Stack
- Find the Winner of an Array Game Simulation
- Queries on a Permutation With Key Binary Indexed Tree, Simulation
- Corporate Flight Bookings Prefix Sum
- Find the Winner of the Circular Game Math, Recursion, Simulation
- Longest Subsequence With Limited Sum Binary Search, Greedy, Sorting
- Partition Array for Maximum Sum Dynamic Programming
- Stone Game VII Math, Dynamic Programming, Game Theory
- Minimum Number of Work Sessions to Finish the Tasks Dynamic Programming, Bit Manipulation, Bitmask
- Count Fertile Pyramids in a Land Dynamic Programming, Matrix
- Count Ways to Group Overlapping Ranges Sorting, Math
- Find the Integer Added to Array II Two Pointers, Sorting, Enumeration
- Minimum Operations to Exceed Threshold Value II Heap (Priority Queue), Simulation
- Sum of Digit Differences of All Pairs Hash Table, Math, Counting
- Alternating Groups II Sliding Window
- Minimum Sum of Mountain Triplets II Prefix Sum
- Count Days Without Meetings Sorting
- Determine the Minimum Sum of a k-avoiding Array Math, Greedy
- Find the Value of the Partition Sorting
- Maximum Value of an Ordered Triplet II Prefix Sum
- Process Tasks Using Servers Simulation, Heap (Priority Queue)
- Maximum Number of Eaten Apples Greedy, Heap (Priority Queue)
- K-th Smallest Prime Fraction Binary Search, Sorting, Heap (Priority Queue)
- Find K Pairs with Smallest Sums Heap (Priority Queue)
- Maximum Subsequence Score Greedy, Sorting, Heap (Priority Queue)
- Total Cost to Hire K Workers Two Pointers, Simulation, Heap (Priority Queue)
- Single-Threaded CPU Sorting, Heap (Priority Queue)
- Most Beautiful Item for Each Query Binary Search, Sorting
- Number of Orders in the Backlog Simulation, Heap (Priority Queue)
- Maximum Number of Events That Can Be Attended Greedy, Sorting, Heap (Priority Queue)
- The Number of the Smallest Unoccupied Chair Hash Table, Heap (Priority Queue), Ordered Set
- Maximal Score After Applying K Operations Greedy, Heap (Priority Queue)
- Find the Kth Largest Integer in the Array String, Sorting, Heap (Priority Queue)
- Minimum Cost to Connect Sticks Greedy, Heap (Priority Queue)
- Find the Safest Path in a Grid Matrix, Binary Search, Breadth-First Search
- Detonate the Maximum Bombs Math, Graph, Depth-First Search
- The Maze II Matrix, Graph, Breadth-First Search
- Open the Lock String, Breadth-First Search
- Loud and Rich Graph, Topological Sort, Depth-First Search
- Maximum Star Sum of a Graph Graph, Greedy, Sorting
- Reachable Nodes With Restrictions Tree, Graph, Depth-First Search
- Largest Plus Sign Matrix, Dynamic Programming
- Remove All Ones With Row and Column Flips Matrix, Bit Manipulation
- Number of Corner Rectangles Matrix, Math, Dynamic Programming
- Magic Squares In Grid Matrix, Simulation
- Maximum Number of Fish in a Grid Matrix, Depth-First Search, Breadth-First Search
- Construct Product Matrix Matrix, Prefix Sum
- Maximum Number of Moves in a Grid Matrix, Dynamic Programming, Breadth-First Search
- Map of Highest Peak Matrix, Breadth-First Search
- Convert an Array Into a 2D Array With Conditions Matrix, Hash Table
- Check Knight Tour Configuration Matrix, Depth-First Search, Simulation
- First Completely Painted Row or Column Matrix, Hash Table
- Rotating the Box Matrix, Two Pointers, Simulation
- Find All Groups of Farmland Matrix, Depth-First Search, Breadth-First Search
- Matrix Block Sum Matrix, Prefix Sum
- Spiral Matrix III Matrix, Simulation
- Where Will the Ball Fall Matrix, Simulation, Depth-First Search
- Maximum Matrix Sum Matrix, Greedy
- Difference Between Ones and Zeros in Row and Column Matrix, Simulation
- Find the N-th Value After K Seconds Math, Simulation, Prefix Sum
- Minimum Cost Tree From Leaf Values Dynamic Programming, Stack, Monotonic Stack
- The Number of Beautiful Subsets Hash Table, Dynamic Programming, Backtracking
- Stone Game II Dynamic Programming, Prefix Sum, Game Theory
- Predict the Winner Dynamic Programming, Recursion, Game Theory
- Count Alternating Subarrays Math, Dynamic Programming
- Longest Arithmetic Subsequence Hash Table, Dynamic Programming, Binary Search
- Coin Change II Dynamic Programming
- Minimum Impossible OR Bit Manipulation, Brainteaser
- Stone Game IX Math, Greedy, Counting
- Minimum Operations to Make Median of Array Equal to K Greedy, Sorting
- Destroy Sequential Targets Hash Table, Counting
- Smallest Missing Non-negative Integer After Operations Hash Table, Math, Greedy
- Find the Maximum Number of Marked Indices Two Pointers, Greedy, Sorting
- Maximum Consecutive Floors Without Special Floors Sorting, Greedy
- Video Stitching Greedy, Dynamic Programming, Intervals
- Eliminate Maximum Number of Monsters Greedy, Sorting
- Removing Minimum and Maximum From Array Greedy
- Minimum Number of Operations to Move All Balls to Each Box String, Prefix Sum, Greedy
- Minimum Number of Arrows to Burst Balloons Greedy, Sorting, Intervals
- Maximum Number of Removable Characters String, Binary Search, Two Pointers
- Divide Chocolate Binary Search, Greedy
- Successful Pairs of Spells and Potions Binary Search, Sorting, Two Pointers
- Search a 2D Matrix II Matrix, Binary Search, Divide and Conquer
- Find Right Interval Binary Search, Sorting
- House Robber IV Binary Search, Greedy
- Minimize the Maximum Difference of Pairs Binary Search, Greedy, Sorting
- Maximum Candies Allocated to K Children Binary Search
- Peak Index in a Mountain Array Binary Search
- H-Index II Binary Search
- Find the Smallest Divisor Given a Threshold Binary Search
- Find the Student That Will Replace the Chalk Binary Search, Prefix Sum, Simulation
- Minimum Limit of Balls in a Bag Binary Search
- Magnetic Force Between Two Balls Binary Search, Sorting, Greedy
- Minimum Number of Days to Make m Bouquets Binary Search
- Capacity to Ship Packages Within D Days Binary Search
- Find First and Last Position of Element in Sorted Array Binary Search
- Find Minimum in Rotated Sorted Array II Binary Search
- Search in Rotated Sorted Array II Binary Search
- Minimum Consecutive Cards to Pick Up Hash Table, Sliding Window
- Max Consecutive Ones II Sliding Window, Dynamic Programming
- Minimum Swaps to Group All 1's Together II Sliding Window
- Length of Longest Subarray With at Most K Frequency Hash Table, Sliding Window
- Maximum Beauty of an Array After Applying Operation Sliding Window, Sorting, Binary Search
- Count Complete Subarrays in an Array Hash Table, Sliding Window
- Number of Subarrays with Bounded Maximum Sliding Window, Two Pointers
- Count the Number of Good Subarrays Hash Table, Sliding Window, Counting
- Frequency of the Most Frequent Element Sliding Window, Greedy, Sorting
- K Radius Subarray Averages Sliding Window, Prefix Sum
- Maximum Points You Can Obtain from Cards Sliding Window, Prefix Sum
- Grumpy Bookstore Owner Sliding Window
- Sentence Similarity III String, Two Pointers
- Watering Plants II Two Pointers, Simulation
- Number of Subsequences That Satisfy the Given Sum Condition Two Pointers, Sorting, Binary Search
- The k Strongest Values in an Array Two Pointers, Sorting
- 3Sum With Multiplicity Hash Table, Two Pointers, Counting
- Most Profit Assigning Work Two Pointers, Greedy, Sorting
- Longest Mountain in Array Two Pointers, Dynamic Programming
- Partition Array Such That Maximum Difference Is K Greedy, Sorting, Two Pointers
- Sort Transformed Array Two Pointers, Math, Sorting
- Bag of Tokens Two Pointers, Greedy, Sorting
- Max Number of K-Sum Pairs Two Pointers, Hash Table, Sorting
- 4Sum Two Pointers, Sorting
- Maximum Distance Between a Pair of Values Two Pointers, Binary Search
- Maximum OR Bit Manipulation, Greedy, Prefix Sum
- Bitwise ORs of Subarrays Bit Manipulation, Dynamic Programming
- Longest Nice Subarray Bit Manipulation, Sliding Window
- UTF-8 Validation Bit Manipulation
- Maximum XOR for Each Query Bit Manipulation, Prefix Sum
- XOR Queries of a Subarray Bit Manipulation, Prefix Sum
- Decode XORed Permutation Bit Manipulation, Brainteaser
- Find the Xor-Beauty of Array Bit Manipulation, Math, Brainteaser
- Maximum XOR After Operations Bit Manipulation, Brainteaser
- Longest Subarray With Maximum Bitwise AND Bit Manipulation, Brainteaser
- Minimum Number of Operations to Make Array XOR Equal to K Bit Manipulation
- Find The Original Array of Prefix Xor Bit Manipulation, Prefix Sum
- Bitwise XOR of All Pairings Bit Manipulation, Brainteaser
- Minimum Time to Repair Cars Binary Search, Greedy
- Maximum Value of an Ordered Triplet I Math, Prefix Sum
- Maximum Product After K Increments Greedy, Heap
- Prime Subtraction Operation Math, Greedy, Number Theory
- Number of Zero-Filled Subarrays Math, Counting
- 4Sum II Hash Table, Counting
- Find Players With Zero or One Losses Hash Table, Sorting, Counting
- Minimum Area Rectangle Hash Table, Geometry
- Number of Boomerangs Hash Table, Math
- Group the People Given the Group Size They Belong To Hash Table, Greedy
- Count Number of Bad Pairs Hash Table, Counting
- Brick Wall Hash Table, Counting
- Number of Pairs of Interchangeable Rectangles Hash Table, Math, Counting
- Count Nice Pairs in an Array Hash Table, Math, Counting
- Maximum Size Subarray Sum Equals k Hash Table, Prefix Sum
- Longest Well-Performing Interval Hash Table, Prefix Sum, Stack
- Subarray Sums Divisible by K Hash Table, Prefix Sum
- Count Triplets With Sum Smaller Than X Two Pointers, Sorting
- Kth Smallest Element Sorting, Quickselect
- Maximum Index Two Pointers
- Rearrange Array in Max/Min Form Two Pointers
- Subarray With Given Sum Sliding Window, Two Pointers
- Longest Subarray With Sum Zero Hash Table, Prefix Sum
- Minimum Swaps to Sort Sorting, Graph
- Count Inversions Divide and Conquer, Fenwick Tree
- Divide Array Into Arrays With Max Difference Greedy, Sorting
- Count Number of Teams Dynamic Programming
- Uncrossed Lines Dynamic Programming
- Paint House Dynamic Programming
- Find Original Array From Doubled Array Greedy, Sorting, Hash Table
- K-diff Pairs in an Array Hash Table
- Non-decreasing Array Greedy
- Minimum Moves to Equal Array Elements II Math, Sorting
- Minimum Moves to Equal Array Elements Math
- Word Search String, Backtracking, Depth-First Search
- Pacific Atlantic Water Flow Depth-First Search, Breadth-First Search, Matrix
- Snakes and Ladders Breadth-First Search, Matrix
- Jump Game III Depth-First Search, Breadth-First Search
- Path With Minimum Effort Binary Search, Depth-First Search, Breadth-First Search
- Detect Cycles in 2D Grid Depth-First Search, Breadth-First Search, Union Find
- Number of Distinct Islands Hash Table, Depth-First Search, Breadth-First Search
- Shortest Bridge Depth-First Search, Breadth-First Search, Matrix
- The Earliest Moment When Everyone Become Friends Union Find, Sorting
- Count Sub Islands Depth-First Search, Breadth-First Search, Union Find
- As Far from Land as Possible Dynamic Programming, Breadth-First Search, Matrix
- Shortest Path in Binary Matrix Breadth-First Search, Matrix
- Number of Enclaves Depth-First Search, Breadth-First Search, Union Find
- Rotate Function Math, Dynamic Programming
- Count Triplets That Can Form Two Arrays of Equal XOR Hash Table, Math, Bit Manipulation
- Maximum Product of Word Lengths String, Bit Manipulation
- Maximum XOR of Two Numbers in an Array Hash Table, Bit Manipulation, Trie
- Total Hamming Distance Math, Bit Manipulation
- Single Number III Bit Manipulation
- Single Number II Bit Manipulation
- Buildings With an Ocean View Stack, Monotonic Stack
- The Number of Weak Characters in the Game Greedy, Sorting, Stack
- Max Chunks To Make Sorted Stack, Greedy, Monotonic Stack
- Sum of Subarray Ranges Stack, Monotonic Stack
- Reveal Cards In Increasing Order Queue, Sorting, Simulation
- Validate Stack Sequences Stack, Simulation
- Maximum Width Ramp Stack, Monotonic Stack, Two Pointers
- 132 Pattern Binary Search, Stack, Monotonic Stack
- Sum of Subarray Minimums Dynamic Programming, Stack, Monotonic Stack
- Build an Array With Stack Operations Stack, Simulation
- Minimum Number of Platforms Greedy, Sorting, Two Pointers
- Find K Closest Elements Two Pointers, Binary Search, Sorting
- Kth Smallest Element in a Sorted Matrix Binary Search, Sorting, Heap
- Top K Frequent Words Hash Table, String, Sorting
- K Closest Points to Origin Math, Divide and Conquer, Geometry
- Partition Array into Disjoint Intervals Greedy
- Minimum Time to Make Rope Colorful String, Dynamic Programming, Greedy
- Valid Triangle Number Two Pointers, Binary Search, Greedy
- Rearrange Array Elements by Sign Two Pointers, Simulation
- Maximum Number of Coins You Can Get Math, Greedy, Sorting
- Largest Number String, Greedy, Sorting
- Maximum Ice Cream Bars Greedy, Sorting, Counting Sort
- Remove Covered Intervals Greedy, Sorting
- Reduce Array Size to The Half Hash Table, Greedy, Sorting
- Queue Reconstruction by Height Greedy, Sorting, Binary Indexed Tree
- Two City Scheduling Greedy, Sorting
- Maximum Length of Pair Chain Dynamic Programming, Greedy, Sorting
- Longest Turbulent Subarray Dynamic Programming, Sliding Window
- Best Sightseeing Pair Dynamic Programming
- Maximum Sum Circular Subarray Divide and Conquer, Dynamic Programming, Queue
- Minimum Cost For Tickets Dynamic Programming
- Longest String Chain Hash Table, Two Pointers, String
- Combination Sum IV Dynamic Programming
- Ones and Zeroes String, Dynamic Programming
- Last Stone Weight II Dynamic Programming
- Stone Game Math, Dynamic Programming, Game Theory
- Triangle Dynamic Programming
- Minimum Falling Path Sum Dynamic Programming, Matrix
- Arithmetic Slices Dynamic Programming
- Wiggle Subsequence Dynamic Programming, Greedy
- Number of Longest Increasing Subsequence Dynamic Programming, Binary Indexed Tree
- Longest Arithmetic Subsequence of Given Difference Hash Table, Dynamic Programming
- Maximum Length of Repeated Subarray Binary Search, Dynamic Programming, Sliding Window
- Best Time to Buy and Sell Stock with Transaction Fee Dynamic Programming, Greedy
- Best Time to Buy and Sell Stock with Cooldown Dynamic Programming
- Delete and Earn Hash Table, Dynamic Programming
- Valid Sudoku Hash Table, Matrix
- Count Servers that Communicate Depth-First Search, Breadth-First Search, Union Find
- Number of Closed Islands Depth-First Search, Breadth-First Search, Union Find
- Surrounded Regions Depth-First Search, Breadth-First Search, Union Find
- Game of Life Matrix, Simulation
- Count Square Submatrices with All Ones Dynamic Programming, Matrix
- Maximal Square Dynamic Programming, Matrix
- Unique Paths II Dynamic Programming, Matrix
- Minimum Path Sum Dynamic Programming, Matrix
- Sort the Matrix Diagonally Sorting, Matrix
- Max Increase to Keep City Skyline Greedy, Matrix
- Diagonal Traverse Matrix, Simulation
- Spiral Matrix II Matrix, Simulation
- Remove Duplicates from Sorted Array II Two Pointers
- Count Number of Nice Subarrays Hash Table, Math, Sliding Window
- Binary Subarrays With Sum Hash Table, Sliding Window, Prefix Sum
- Maximum Erasure Value Hash Table, Sliding Window
- Minimum Operations to Reduce X to Zero Hash Table, Binary Search, Sliding Window
- Longest Subarray of 1's After Deleting One Element Dynamic Programming, Sliding Window
- Continuous Subarray Sum Hash Table, Math, Prefix Sum
- Contiguous Array Hash Table, Prefix Sum
- Subarray Product Less Than K Sliding Window, Binary Search, Prefix Sum
- Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold Sliding Window
- Majority Element II Hash Table, Sorting, Counting
- Increasing Triplet Subsequence Greedy
- H-Index Sorting, Counting Sort
- Shortest Unsorted Continuous Subarray Two Pointers, Sorting, Monotonic Stack
- Next Permutation Two Pointers
- Find All Duplicates in an Array Hash Table
- Combination Sum Backtracking
- Permutations Backtracking
- Subsets Backtracking, Bit Manipulation
- 3Sum Closest Two Pointers, Sorting
- 3Sum Two Pointers, Sorting
- Car Pooling Prefix Sum, Intervals, Sorting
- Interval List Intersections Two Pointers, Intervals
- Minimum Number of Arrows to Burst Balloons Greedy, Sorting, Intervals
- Meeting Rooms II Sorting, Heap, Intervals
- Non-overlapping Intervals Greedy, Sorting, Intervals
- Insert Interval Intervals
- Merge Intervals Sorting, Intervals
- 01 Matrix Matrix, Breadth-First Search, Dynamic Programming
- Rotting Oranges Matrix, Breadth-First Search
- Max Area of Island Matrix, Depth-First Search
- Number of Islands Matrix, Depth-First Search, Breadth-First Search
- Search a 2D Matrix Matrix, Binary Search
- Set Matrix Zeroes Matrix, Hash Table
- Spiral Matrix Matrix, Simulation
- Rotate Image Matrix, Math
- Furthest Building You Can Reach Heap, Greedy
- Least Number of Unique Integers after K Removals Heap, Greedy, Hash Table
- Sort an Array Sorting, Heap, Divide and Conquer
- Top K Frequent Elements Heap, Hash Table, Bucket Sort
- Kth Largest Element in an Array Heap, Quickselect, Sorting
- Target Sum Dynamic Programming, Backtracking
- Partition Equal Subset Sum Dynamic Programming
- Longest Increasing Subsequence Dynamic Programming, Binary Search
- Coin Change II Dynamic Programming
- Coin Change Dynamic Programming, Breadth-First Search
- House Robber II Dynamic Programming
- House Robber Dynamic Programming
- Task Scheduler Greedy, Heap, Counting
- Boats to Save People Greedy, Two Pointers, Sorting
- Best Time to Buy and Sell Stock II Greedy, Dynamic Programming
- Hand of Straights Greedy, Hash Table, Sorting
- Gas Station Greedy
- Jump Game II Greedy, Dynamic Programming
- Jump Game Greedy, Dynamic Programming
- Car Fleet Stack, Sorting, Monotonic Stack
- Asteroid Collision Stack, Simulation
- Next Greater Element II Stack, Monotonic Stack
- Daily Temperatures Stack, Monotonic Stack
- Evaluate Reverse Polish Notation Stack, Math
- Single Element in a Sorted Array Binary Search
- Capacity To Ship Packages Within D Days Binary Search, Greedy
- Koko Eating Bananas Binary Search
- Find First and Last Position of Element in Sorted Array Binary Search
- Find Peak Element Binary Search
- Find Minimum in Rotated Sorted Array Binary Search
- Search in Rotated Sorted Array Binary Search
- Sort Colors Two Pointers, Sorting
- Fruit Into Baskets Sliding Window, Hash Table
- Max Consecutive Ones III Sliding Window, Binary Search
- Minimum Size Subarray Sum Sliding Window, Prefix Sum
- Container With Most Water Two Pointers, Greedy
- Two Sum II - Input Array Is Sorted Two Pointers, Binary Search
- Find the Duplicate Number Two Pointers, Binary Search
- Longest Consecutive Sequence Hash Table, Union Find
- Subarray Sum Equals K Hash Table, Prefix Sum
- Maximum Product Subarray Dynamic Programming
- Rotate Array Math, Two Pointers
- Product of Array Except Self Prefix Sum
- Maximum Subarray Dynamic Programming, Divide and Conquer
Hard (91)
- Count Ways to Make Array With Product Math, Dynamic Programming, Combinatorics
- The Number of Good Subsets Math, Dynamic Programming, Bit Manipulation
- Number of Ways to Reorder Array to Get Same BST Math, Divide and Conquer, Dynamic Programming
- Make Array Strictly Increasing Binary Search, Dynamic Programming, Sorting
- Odd Even Jump Dynamic Programming, Stack, Monotonic Stack
- Maximum Number of Events That Can Be Attended II Binary Search, Dynamic Programming, Sorting
- Minimum Replacements to Sort the Array Math, Greedy
- Create Sorted Array Through Instructions Binary Search, Divide and Conquer, Binary Indexed Tree
- Painting the Walls Dynamic Programming
- Reverse Pairs Binary Search, Divide and Conquer, Binary Indexed Tree
- Minimum Incompatibility Dynamic Programming, Bit Manipulation, Bitmask
- Form Largest Integer With Digits That Add up to Target String, Dynamic Programming
- Stone Game VIII Math, Dynamic Programming, Prefix Sum
- Allocate Mailboxes Math, Dynamic Programming, Sorting
- Constrained Subsequence Sum Dynamic Programming, Queue, Sliding Window
- Maximum Height by Stacking Cuboids Dynamic Programming, Sorting
- Cherry Pickup II Dynamic Programming, Matrix
- Maximum Value of K Coins From Piles Dynamic Programming, Prefix Sum
- Number of Great Partitions Dynamic Programming
- Minimum Cost to Split an Array Hash Table, Dynamic Programming, Counting
- Paths in Matrix Whose Sum Is Divisible by K Dynamic Programming, Matrix
- Apply Operations to Maximize Score Math, Stack, Greedy
- Meeting Rooms III Sorting, Simulation, Heap (Priority Queue)
- Smallest Range Covering Elements from K Lists Hash Table, Greedy, Sliding Window
- Minimize Deviation in Array Greedy, Heap (Priority Queue), Ordered Set
- Maximum Performance of a Team Greedy, Sorting, Heap (Priority Queue)
- Construct Target Array With Multiple Sums Heap (Priority Queue), Math
- Minimum Number of Operations to Make Array Continuous Hash Table, Binary Search, Sliding Window
- Put Marbles in Bags Greedy, Sorting, Heap (Priority Queue)
- Minimum Time to Visit a Cell In a Grid Matrix, Graph, Breadth-First Search
- Minimum Number of Days to Disconnect Island Matrix, Depth-First Search, Breadth-First Search
- Number of Increasing Paths in a Grid Matrix, Dynamic Programming, Depth-First Search
- Checking Existence of Edge Length Limited Paths Union Find, Graph, Sorting
- Minimum Obstacle Removal to Reach Corner Matrix, Graph, Breadth-First Search
- Number of Good Paths Tree, Graph, Union Find
- Largest Component Size by Common Factor Math, Union Find, Number Theory
- Bus Routes Hash Table, Breadth-First Search
- Sliding Puzzle Matrix, Breadth-First Search
- Jump Game IV Hash Table, Breadth-First Search
- Trapping Rain Water II Matrix, Heap (Priority Queue), Breadth-First Search
- Escape the Spreading Fire Matrix, Binary Search, Breadth-First Search
- Grid Illumination Hash Table, Matrix
- Shortest Distance from All Buildings Matrix, Breadth-First Search
- Minimum Moves to Spread Stones Over Grid Matrix, Dynamic Programming, Breadth-First Search
- Making A Large Island Matrix, Depth-First Search, Breadth-First Search
- Unique Paths III Matrix, Backtracking, Bit Manipulation
- Number of Submatrices That Sum to Target Matrix, Hash Table, Prefix Sum
- Longest Increasing Path in a Matrix Matrix, Dynamic Programming, Depth-First Search
- Maximal Rectangle Matrix, Stack, Dynamic Programming
- Minimum Difficulty of a Job Schedule Dynamic Programming
- Minimum Cost to Cut a Stick Dynamic Programming, Sorting
- Maximum Number of Groups With Increasing Length Greedy, Sorting, Binary Search
- Number of Ways to Earn Points Dynamic Programming
- Profitable Schemes Dynamic Programming
- Cherry Pickup Matrix, Dynamic Programming
- Tallest Billboard Dynamic Programming
- Best Time to Buy and Sell Stock IV Dynamic Programming
- Burst Balloons Dynamic Programming
- Frog Jump Hash Table, Dynamic Programming
- Minimum Falling Path Sum II Matrix, Dynamic Programming
- Dungeon Game Matrix, Dynamic Programming
- Minimum Time to Complete All Tasks Greedy, Sorting
- Minimum Number of Refueling Stops Greedy, Dynamic Programming, Heap
- IPO Greedy, Sorting, Heap
- Minimum Number of Taps to Open to Water a Garden Greedy, Dynamic Programming, Intervals
- Maximum Number of Tasks You Can Assign Binary Search, Greedy, Sorting
- Find the Kth Smallest Sum of a Matrix With Sorted Rows Matrix, Binary Search, Heap
- Russian Doll Envelopes Binary Search, Dynamic Programming, Sorting
- Maximum Running Time of N Computers Binary Search, Greedy, Sorting
- Minimum Time to Complete Trips Binary Search
- Split Array Largest Sum Binary Search, Greedy, Dynamic Programming
- Minimum Number of K Consecutive Bit Flips Sliding Window, Prefix Sum, Greedy
- Shortest Subarray with Sum at Least K Prefix Sum, Sliding Window, Monotonic Queue
- Count Subarrays With Fixed Bounds Sliding Window, Two Pointers, Queue
- Maximum Number of Robots Within Budget Sliding Window, Two Pointers, Queue
- Find K-th Smallest Pair Distance Two Pointers, Binary Search, Sorting
- Subarrays with K Different Integers Hash Table, Sliding Window, Two Pointers
- Find Subarray With Bitwise OR Closest to K Bit Manipulation, Binary Search, Segment Tree
- Largest Multiple of Three Greedy, Dynamic Programming, Math
- Max Value of Equation Monotonic Queue, Sliding Window
- Count of Smaller Numbers After Self Fenwick Tree, Divide and Conquer
- Stone Game III Dynamic Programming, Game Theory
- Max Dot Product Between Two Subsequences Dynamic Programming
- Swim in Rising Water Binary Search, Depth-First Search, Breadth-First Search
- Number of Visible People in a Queue Stack, Monotonic Stack
- Best Time to Buy and Sell Stock III Dynamic Programming
- Candy Greedy
- Largest Rectangle in Histogram Stack, Monotonic Stack
- Sliding Window Maximum Sliding Window, Monotonic Queue, Heap
- Trapping Rain Water Two Pointers, Dynamic Programming, Stack
- First Missing Positive Hash Table
Companies that ask arrays problems
- Amazon 552 problems on arrays
- Google 372 problems on arrays
- Microsoft 119 problems on arrays
- Adobe 112 problems on arrays
- Meta 78 problems on arrays
- TCS 63 problems on arrays
- Infosys 40 problems on arrays
- Uber 33 problems on arrays
- Flipkart 29 problems on arrays
- Wipro 22 problems on arrays
- Bloomberg 21 problems on arrays
- Zoho 20 problems on arrays
Next topic: Strings