Data structure interview questions are a core part of software engineer interviews at companies such as Meta, Google, or Amazon.
That's why we've compiled a comprehensive list of 73 typical questions grouped by type (arrays, strings, linked list, etc.) and included links to high quality solutions.
We've also included the ultimate cheat sheet, giving you key information on space-time complexity for each data structure at a glance.
Here's a summary of what you'll find below:
- Data structure cheat sheet
- Array questions
- String questions
- Linked list questions
- Stacks and queues questions
- Tree questions
- Graph questions
- Map questions
- Heap questions
- How to prepare for a coding interview
Let's get into it!
Click here to practice 1-on-1 with FAANG ex-interviewers
1. The ultimate data structure cheat sheet
When you're preparing for coding interviews, it helps to have at least some of the key information in one place. We've created an 8-page cheat sheet, which you can use as a handy reference point for the 8 main data structures.
Click here to download the data structure interview cheat sheet as a PDF.
Right, let's take a look at some typical data structure questions.
2. Arrays
Arrays are one of the most fundamental data structures in programming and computer science, and many more complex data structures are built using arrays. Learn more.
2.1 Easy array questions
2.1.1 Merge two sorted arrays
- Text guide (GeeksforGeeks)
- Video guide (TECH DOSE)
2.1.2 Remove duplicates from an array
- Video guide (Kevin Naughton Jr.)
- Text guide (W3Schools)
- Text guide (Javarevisted)
- Code example (LeetCode)
2.1.3 Count the frequency of an element in an array
- Text guide (GeeksforGeeks)
- Video guide (SDET)
2.2 Medium array questions
2.2.1 Move all zeros to the beginning/end of an array
- Text guide (Educative)
- Video guide (Programming tutorials)
- Code example (LeetCode)
2.2.2 Find if a given element is in a sorted array (binary search)
- Text guide (Khan academy)
- Video guide (HackerRank)
- Code example (LeetCode)
2.2.3 Rotate an array
- Text guide (GeeksforGeeks)
- Video guide (Nick White)
- Code example (LeetCode)
2.2.4 Product Array Puzzle
-
- Text guide (TutorialCup)
- Text guide (Akhilpokle)
- Video guide (Nick White)
2.3 Hard array questions
2.3.1 Rotate a 2D array
- Text guide (Jack)
- Text guide (GeeksforGeeks)
- Video guide (Nick White)
2.3.2 Create change with coins (dynamic programming)
- Text guide (Educative)
- Video guide (Back to Back SWE)
2.3.3 Sliding window maximum
- Text guide (After Academy)
- Video guide (Jessica Lin)
How did you get on? To practice with more array questions like this, check out our list of 50+ array questions with solutions.
3. Strings
A string is an ordered sequence, or string, of characters. It is usually considered a data type and is often included as part of language primitives. In most languages, strings are implemented using an array of bytes. The bytes are encoded using some character encoding. Earlier systems used ASCII encoding, with Unicode encoding used in later systems. Learn more.
3.1 Easy string questions
3.1.1 Remove vowels from a string
- Text guide (GeeksforGeeks)
- Video guide (Kevin Naughton Jr.)
3.1.2 Defanging an IP address
- Text guide (GeeksforGeeks)
- Video guide (Kevin Naughton Jr.)
- Code example (LeetCode)
3.1.3 Jewels and stones
- Text guide (Memogrocery)
- Video guide (Kevin Naughton Jr.)
- Code example (LeetCode)
3.2 Medium string questions
3.2.1 Longest substring without repeating characters
- Text guide (Medium/Nerd For Tech)
- Video guide (Michael Muinos)
- Code example (LeetCode)
3.2.2 Longest palindromic substring
- Text guide (RedQuark)
- Video guide (NeetCode)
- Video guide (Errichto)
3.2.3 String to integer (atoi)
- Text guide (Medium/Hary)
- Video guide (TECH DOSE)
- Code example (LeetCode)
3.3 Hard string questions
3.3.1 Regular expression matching
- Text guide (RedQuark)
- Video guide (NeetCode)
- Code example (LeetCode)
3.3.2 Wildcard matching
- Text guide (Techie Delight)
- Video guide (Tushar Roy)
- Code example (LeetCode)
3.3.3 Minimum window substring
- Text guide (Medium/Algo Shaft)
- Video guide (Back to Back SWE)
- Code example (LeetCode)
Keen to work through some more? See our article, 50+ string questions and solutions. That should keep you busy for a while!
4. Linked lists
A linked list is a data structure used to store a collection of data elements. In this way, it is similar to an array. However, unlike an array, the data elements in a linked list do not need to be stored contiguously in memory. Rather, each node in a linked list has a pointer or reference to the memory location of the next node in the list. This means that linked lists do not have a fixed size like arrays, and can easily grow and shrink as elements are added or removed. Learn more.
4.1 Easy linked list questions
4.1.1 Merge two sorted lists
- Text guide (RedQuark)
- Video guide (Kevin Naughton Jr.)
- Code example (LeetCode)
4.1.2 Linked list cycle
- Text guide (GeeksforGeeks)
- Video guide (NeetCode)
- Code example (LeetCode)
4.1.3 Intersection of two linked lists
- Text guide (Dev.to/Seanpgallivan)
- Video guide (Nick White)
- Code example (LeetCode)
4.2 Medium linked list questions
4.2.1 Add two numbers
- Text guide (RedQuark)
- Video guide (NeetCode)
- Code example (LeetCode)
4.2.2 Remove Nth node from end of list
- Text guide (RedQuark)
- Video guide (NeetCode)
- Code example (LeetCode)
4.2.3 Copy list with random pointer
- Text guide (GeeksforGeeks)
- Video guide (Back to Back SWE)
- Code example (LeetCode)
4.3 Hard linked list questions
4.3.1 Design linked list
- Text guide (Medium/ Len Chen)
- Video guide (Simon Schueller)
- Code example (LeetCode)
4.3.2 Merge k sorted lists
- Text guide (After Academy)
- Video guide (Kevin Naughton Jr.)
- Video guide (NeetCode)
- Code example (LeetCode)
4.3.3 Reverse nodes in k-group
- Text guide (RedQuark)
- Video guide (NeetCode)
- Code example (LeetCode)
For more questions like these, check out our list of 40+ linked list questions and solutions.
5. Stacks and queues
Stacks and queues are similar and complementary in many ways. Both are a sequenced collection of elements that are generally accessed one element at time, and they are implemented using similar data structures. Learn more.
5.1 Easy stacks and queues questions
5.1.1 Valid parenthesis
- Text guide (RedQuark)
- Video guide (NeetCode)
- Code example (LeetCode)
5.1.2 Min stack
- Text guide (After Academy)
- Video guide (NeetCode)
- Video guide (Nick White)
- Code example (LeetCode)
5.1.3 Implement stack using queues
- Text guide (LeetCode)
- Video guide (TECH DOSE)
- Code example (LeetCode)
5.2 Medium stacks and queues questions
5.2.1 Simplify path
- Text guide (LeetCode)
- Video guide (NeetCode)
- Code example (LeetCode)
5.2.2 Evaluate reverse polish notation
- Text guide (Dev.to/Rohith V)
- Video guide (Back to Back SWE)
- Code example (LeetCode)
5.2.3 Basic calculator II
- Text guide (Calvin Chan)
- Video guide (happygirlzt)
- Code example (LeetCode)
5.3 Hard stacks and queues questions
5.3.1 Longest valid parentheses
- Text guide (Dev.to/Seanpgallivan)
- Video guide (Time Complexity Infinity)
- Code example (LeetCode)
5.3.2 Trapping rain water
- Text guide (After Academy)
- Text guide (LeetCode)
- Code example (LeetCode)
5.3.3 Largest rectangle in histogram
- Text guide (GeeksForGeeks)
- Video guide (TECH DOSE)
- Code example (LeetCode)
Need some more stacks and queues questions to practice with? No problem, we've got plenty more here: 50+ stacks and queues questions and solutions.
6. Trees
A tree is an abstract hierarchical data structure. It is represented by a group of linked nodes, with a single root node. Each node can have zero or multiple children. A leaf is a node with no children. Learn more.
6.1 Easy tree questions
6.1.1 Binary tree in-order traversal
- Text guide (LeetCode)
- Video guide (Nick White)
- Code example (LeetCode)
6.1.2 Symmetric tree
- Text guide (GeeksForGeeks)
- Video guide (Kevin Naughton Jr.)
- Video guide (Back to Back SWE)
- Code example (LeetCode)
6.1.3 Maximum depth of binary tree
- Text guide (Medium/Sara)
- Video guide (NeetCode)
- Code example (LeetCode)
6.2 Medium tree questions
6.2.1 Validate binary search tree
- Text guide (Baeldung)
- Video guide (Kevin Naughton Jr.)
- Code example (LeetCode)
6.2.2 Binary tree level-order traversal
- Text guide (Educative.io)
- Video guide (NeetCode)
- Video guide (Back to Back SWE)
- Code example (LeetCode)
6.2.3 Binary tree zigzag level-order traversal
- Text guide (Medium/Hary)
- Video guide (Knowledge Center)
- Code example (LeetCode)
6.3 Hard tree questions
6.3.1 Binary tree maximum path sum
- Text guide (LeetCode)
- Text guide (After Academy)
- Video guide (Michael Muinos)
- Code example (GeeksForGeeks)
6.3.2 Serialize and deserialize binary tree
- Text guide (Educative.io)
- Video guide (Back to Back SWE)
- Video guide (NeetCode)
- Code example (LeetCode)
6.3.3 Binary tree cameras
- Text guide (Dev.to/Seanpgallivan)
- Video guide (Algorithms Made Easy)
- Video guide (happygirlzt)
- Code example (LeetCode)
Check out plenty more tree questions here: 50+ tree questions and solutions.
7. Graphs
A graph is an abstract data structure represented by vertices connected by edges. Vertices are also known as nodes. Vertices sharing an edge are known as adjacent. Learn more.
7.1 Easy graph questions
7.1.1 Find the town judge
- Text guide (Medium/Omar Faroque)
- Video guide (Nick White)
- Video guide (TECH DOSE)
- Code example (LeetCode)
7.1.2 Find if path exists in graph
- Text guide (GeeksForGeeks)
- Video guide (CodeClips)
- Code example (LeetCode)
7.1.3 Find center of star graph
- Text guide (GoodTeacher)
- Video guide (Cherry Coding)
- Code example (LeetCode)
7.2 Medium graph questions
7.2.1 Course schedule II
- Text guide (LeetCode)
- Video guide (NeetCode)
- Code example (LeetCode)
7.2.2 Find the celebrity
- Text guide (Medium/Zhuozhuo Liu)
- Video guide (Kevin Naughton Jr.)
- Code example (Zirui)
7.2.3 Clone graph
- Text guide (Medium/Deeksha Sharma)
- Video guide (NeetCode)
- Code example (LeetCode)
7.3 Hard graph questions
7.3.1 Longest increasing path in a matrix
- Text guide (Dev.to/Seanpgallivan)
- Video guide (Michael Muinos)
- Code example (LeetCode)
7.3.2 Alien dictionary
- Text guide (Medium/Feng Wang)
- Video guide (NeetCode)
- Video guide (happygirlzt)
- Code example (Tenderleo)
7.3.3 Redundant connection II
- Text guide (Seanforfun)
- Video guide (happygirlzt)
- Code example (LeetCode)
For plenty more graph questions, see 50+ graph interview questions.
8. Maps
A map is a data structure that allows us to access a value by key. This is in contrast to an array that allows us to access a value by index. A common kind of map is a hash map (also called a hash table), which stores keys along with associated values (for example, a telephone directory which associates phone numbers with names). Learn more.
8.1 Easy map questions
8.1.1 Two sum
- Text guide (Medium/Hyewon Cho)
- Video guide (NeetCode)
- Code example (LeetCode)
8.1.2 Roman to integer
- Text guide (Medium/Nerd For Tech)
- Video guide (Java Brains)
- Code example (LeetCode)
8.1.3 Majority element
- Text guide (LeetCode)
- Video guide (Kevin Naughton Jr.)
- Video guide (take u forward)
- Code example (LeetCode)
8.2 Medium map questions
8.2.1 Longest substring without repeating characters
- Text guide (RedQuark)
- Video guide (Michael Muinos)
- Code example (LeetCode)
8.2.2 Valid sudoku
- Text guide (GeeksForGeeks)
- Video guide (Nick White)
- Code example (LeetCode)
8.2.3 Group anagrams
- Text guide (Dev.to/Justin Bermudez)
- Video guide (NeetCode)
- Code example (LeetCode)
8.3 Hard map questions
8.3.1 Minimum window substring
- Text guide (Medium/Algo Shaft)
- Video guide (NeetCode)
- Video guide (Michael Muinos)
- Code example (LeetCode)
8.3.2 Word ladder
- Text guide (GeeksForGeeks)
- Video guide (NeetCode)
- Video guide (Nick White)
- Code example (LeetCode)
8.3.3 Word break II
- Text guide (Educative.io)
- Video guide (babybear4812)
- Code example (LeetCode)
You can find lots more map questions to practice with right here: 50+ map interview questions.
9. Heaps
A heap is a tree-based data structure that implements a priority queue. A priority queue functions much like a regular stack or queue, except that each element has a priority. It is this priority that determines which element is returned when dequeuing from the priority queue, rather than the order in which the element was added. This is useful for applications like a hospital queue where we want to serve the patient with the highest priority first. Learn more.
9.1 Easy heap questions
9.1.1 Kth largest element in a stream
- Text guide (LeetCode)
- Text guide (OpenGenus)
- Video guide (Coding Simplified)
- Code example (LeetCode)
9.1.2 Last stone weight
- Text guide (Tutorial Cup)
- Video guide (Kevin Naughton Jr.)
- Video guide (NeetCode)
- Code example (LeetCode)
9.1.3 The K weakest rows in a matrix
- Text guide (Dev.to/seanpgallivan)
- Video guide (Algorithms Made Easy)
- Code example (LeetCode)
9.2 Medium heap questions
9.2.1 Kth largest element in an array
- Text guide (GeeksForGeeks)
- Video guide (Back to Back SWE)
- Video guide (Kevin Naughton Jr.)
- Code example (LeetCode)
9.2.2 Meeting rooms II
- Text guide (Zirui)
- Video guide (NeetCode)
- Video guide (Kevin Naughton Jr.)
- Code example (Seanforfun)
9.2.3 Top K frequent elements
- Text guide (LeetCode)
- Video guide (NeetCode)
- Code example (LeetCode)
9.3 Hard heap questions
9.3.1 Kth largest element in an array
- Text guide (GeeksForGeeks)
- Video guide (Back to Back SWE)
- Video guide (Kevin Naughton Jr.)
- Code example (LeetCode)
9.3.2 Meeting rooms II
- Text guide (Zirui)
- Video guide (NeetCode)
- Video guide (Kevin Naughton Jr.)
- Code example (Seanforfun)
9.3.3 Top K frequent elements
- Text guide (LeetCode)
- Video guide (NeetCode)
- Code example (LeetCode)
For lots more heap questions, see our article 50+ heap interview questions and cheat sheet.
10. How to prepare for a coding interview
If you're reading this article, it probably means that you're already up and running on the most important step towards preparing to ace a coding interview at Meta, Google, Amazon, Microsoft, LinkedIn, Airbnb or another tech company: practicing a lot of questions.
However, that's not all you need to be confident of killing it in an interview situation. To make sure you're really, truly prepared, we recommend following the three steps below. For extra tips, take a look at our list of 21 coding tips from ex-interviewers.
10.1 Refresh your knowledge
To refresh your knowledge, and to review relevant data structures and algorithms, check out our specific guides:
Data structures:
Algorithms:
- Depth-first search
- Breadth-first search
- Binary search
- Sorting
- Dynamic programming
- Greedy algorithms
- Backtracking
- Divide and conquer
To review big-O notation in order to assess the time and space requirements of your algorithms, study our complete guide on big-O notation and complexity analysis.
10.2 Learn a framework
We recommend getting used to the step-by-step approach explained in the video below. The video was made by Amazon, but it's relevant for coding interviews at any tech company.
Here is a summary of the approach:
- Step 1: Clarify
- Ask clarification questions to remove ambiguity about the problem
- Explore the edges of the problem
- Step 2: Plan
- Discuss potential approaches you could take
- Pick an approach and lay out the high level steps
- Step 3: Implement
- Write clean code, not pseudocode
- Comment on your code as you go
- Step 4: Test
- Start by testing with a simple example
- Try breaking your code with edge and corner cases
- Step 5: Optimize
- Calculate time complexity
- Discuss how you can optimize your solution
For a complete breakdown of this framework, and a full example answer, take a look at our guide on how to answer coding interview questions.
Once you're comfortable with a framework, you'll want to start putting it into practice. This brings us to the next step:
10.3 Practice on your own
To practice data structure questions, we recommend going through the questions we've listed above and trying to solve each one. If you find you need more questions on any of the topics, simply click on the links we've provided.
For algorithm questions, we recommend using our article 71 algorithm interview questions, which has links to high quality answers to each problem. It's organized by type of algorithm and difficulty level. Don't forget to practice questions on a whiteboard or simple text editor instead of an IDE.
10.4 Practice with others
Practicing solving coding problems on your own is a great way to prepare, but it's not enough. If you make it to the onsite interview stage, you'll be expected to code on a whiteboard (or virtual equivalent) and talk through your approach as you code. This can be really tricky if you're not used to it.
That's why we recommend practicing with experts who can give you insightful feedback. If you know a software engineer or similar who has experience running interviews at the company you're interviewing at, then that's fantastic. But for most of us, it's tough to find the right connections to make this happen. And it might also be difficult to practice multiple hours with that person unless you know them really well.
Here's the good news. We've already made the connections for you. We’ve created a coaching service where you can practice 1-on-1 with ex-interviewers from leading tech companies like Meta, Google, and Amazon. Learn more and start scheduling sessions today.