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

Related

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.