Skip to content
DSA arrays 5 min read

Array Exercises: Practice Problems (with Solutions)

Time to practice. Solve each problem yourself first — write the code, trace a small example by hand, and reason about its time and space complexity. Only then open the answer sheet. Every View answer link jumps to a full, multi-language solution on the array solutions page.

How to practice: Set a timer (15–20 min per problem). If you’re stuck, re-read the arrays introduction before peeking. Getting stuck and recovering is how the patterns stick.

Warm-ups

Q1. Reverse an array in place. Given an array, reverse the order of its elements without allocating a second array. Target O(n) time and O(1) extra space.

View answer →

Q2. Find the maximum element. Return the largest value in an array of integers in a single pass. What should you return for an empty array?

View answer →

Q3. Sum of all elements. Compute the sum of an integer array. State the time and space complexity.

View answer →

Core problems

Q4. Two Sum. Given an array nums and a target, return the indices of the two numbers that add up to the target. Can you do better than the obvious O(n²)?

View answer →

Q5. Move zeros to the end. Move all 0s to the end of the array while keeping the relative order of the non-zero elements, in place.

View answer →

Challenge

Q6. Maximum subarray sum (Kadane’s algorithm). Find the largest sum of any contiguous subarray. Aim for a single O(n) pass.

View answer →


Done? Review every solution on the array answer sheet — even the ones you solved, since there’s often a cleaner approach. Then continue to linked lists.

Last updated June 25, 2026
Was this helpful?