Array and String Interview Questions
How to approach array and string questions
Array and string questions check the basics: clean loops, correct indexes, and careful handling of edge cases like an empty input or a single item. They're also where interviewers push you past the first working answer toward a faster one.
A handful of techniques cover most of them: two pointers that walk toward each other (or one fast and one slow), a single pass that tracks the best answer so far, sorting the input first, and a hash map that remembers what you've already seen. Many questions also ask you to work in place, using only O(1) extra space, by swapping items within the array instead of building a new one.
Strings add a wrinkle. In Java, Python and JavaScript, strings are immutable, so building a string by concatenating inside a loop can take O(n²) time. Collect the pieces in a list or a string builder and join them at the end.
Interview Cake isn't just another question database. Each question below walks you through the problem step by step, with hints and explanations as you need them, just like a real interviewer.
Array and string practice questions
Merge overlapping meeting time ranges into condensed blocks: the classic merge intervals problem, with a step-by-step O(n lg n) solution. keep reading »
Reverse String in Place »Write a function to reverse a string in place. keep reading »
Reverse Words »Write a function to reverse the word order of a string, in place. It's to decipher a supersecret message and head off a heist. keep reading »
Merge Sorted Arrays »Write a function for consolidating cookie orders and taking over the world. keep reading »
Cafe Order Checker »Write a function to tell us if cafe customer orders are served in the same order they're paid for. keep reading »
Keep going with the Array and string manipulation section of our coding interview course.
Concepts to review
- Arrays: How arrays are laid out in memory, and why looking up an item by index is O(1).
- Dynamic arrays: Arrays that grow as you append, like Python lists and Java ArrayLists.
- Array slicing: Handy, but it copies: a slice of length k costs O(k) time and space.
- In-place algorithms: Changing the input directly with O(1) extra space, which many array questions ask for.
- Hash tables: The go-to tool for counting characters and finding pairs in one pass.
- Binary search: Finding an item in a sorted array in O(log n) time.
Quick reference: Big O cheat sheet · Data structures cheat sheet
Array and string interview FAQ
What are the most common array interview questions?
What is the two-pointer technique?
What does "in place" mean in an array question?
How do you reverse a string in place?
Are strings just arrays of characters?
More interview questions by topic
- Hash table interview questions
- Greedy algorithm interview questions
- Sorting and binary search interview questions
- Binary tree and BST interview questions
- Graph interview questions
- Dynamic programming and recursion interview questions
- Stack and queue interview questions
- Linked list interview questions
- Bit manipulation interview questions
- System design interview questions
- All coding interview questions
Interview Cake