Array Problems for Coding Interviews
Arrays are the most common interview data structure, because nearly every problem can be phrased over one. The patterns that unlock most of them are two pointers, sliding window, prefix sums, in-place swaps and sorting first. Learn to recognise which pattern a statement hints at before writing any code.
Practise by reading the constraints: a sorted input suggests two pointers or binary search; a subarray with a sum or length condition suggests a sliding window or prefix sums; in-place with O(1) space suggests swapping and index tricks. Each problem below links to a runnable editor with test cases.
Coding problems
- Two Sum (Basic)
- Contains Duplicate (Basic)
- Best Time to Buy and Sell Stock (Basic)
- Maximum Subarray (Intermediate)
- Product of Array Except Self (Intermediate)
- Move Zeroes (Basic)
- Search Insert Position (Basic)
- Rotate Array (Intermediate)
- House Robber (Intermediate)
- Coin Change (Intermediate)
- Longest Increasing Subsequence (Advanced)
- Maximum Product of Two Values (Basic)
- Kth Largest Element (Intermediate)
- Count Inversions (Advanced)
- Single Number (Basic)
- Majority Element (Basic)
- Missing Number (Basic)
- Intersection of Two Arrays (Basic)
- Merge Two Sorted Arrays (Basic)
- Two Sum in a Sorted Array (Basic)
- Count Distinct Values (Basic)
- Minimum Size Subarray Sum (Intermediate)
- Longest Consecutive Sequence (Intermediate)
- Subarray Sum Equals K (Intermediate)
- Container With Most Water (Intermediate)
- Trapping Rain Water (Advanced)
- Jump Game I (Intermediate)
- Partition Into Equal Halves (Advanced)
- Greatest Common Divisor of an Array (Basic)
- Sort Colors (Basic)
- Remove Element (Basic)
- Remove Duplicates Keeping Order (Basic)
- Third Maximum Number (Basic)
- Max Consecutive Ones (Basic)
- Find Pivot Index (Basic)
- Running Sum of Array (Basic)
- Squares of a Sorted Array (Basic)
- Largest Rectangle in Histogram (Advanced)
- Next Greater Value (Intermediate)
- Daily Temperatures (Intermediate)
- Valid Mountain Array (Basic)
- Minimum Moves to Equal Values (Intermediate)
- Min Cost Climbing Stairs (Intermediate)
- Coin Change Ways (Advanced)
- Target Sum (Advanced)
- Plus One (Basic)
- Sort Array by Parity (Basic)
- Largest Number From Digits (Advanced)
- Search in a Rotated Sorted Array (Advanced)
- Minimum in a Rotated Sorted Array (Intermediate)
- Peak Index in a Mountain Array (Intermediate)
- Concatenation of an Array (Basic)
- Sum of Unique Values (Basic)
- Maximum Sum of a Window (Basic)
- Decode XORed Array (Basic)
- Find All Missing Numbers (Basic)
- Next Arrangement (Advanced)
- Merge Intervals (Intermediate)
- Insert an Interval (Intermediate)
- Longest Run of Ones After One Deletion (Intermediate)
Related
- Sliding window problems
- Dynamic programming problems
- Graph problems
- Practice coding problems online
- All interview question topics
Frequently asked questions
How do I get good at array problems?
Solve a few problems of each difficulty, name the pattern after you solve each one, and revisit the ones you needed hints for a week later. The list on this page is ordered so you can start with the basic ones.
Can I run array problems online here?
Yes. Every problem opens in an editor that runs your code against test cases in Java, Python, C++, Go, JavaScript and six more languages, with no setup.