# 55+ Data Structure Interview Questions

Data Structures are an important topic to prepare for interviews at FAANG and other Tier-1 tech companies. Interviewers check your problem-solving skills in various data structures like arrays, trees, graphs, etc.

In this article, we look at some interview questions in data structures.

To help with your interview prep, check out our technical interview checklist, interview questions page, and salary negotiation e-book to **get interview-ready!** Also, read the Best Way to Learn Data Structures and Algorithms to understand how to prepare for data-structure-related questions.

Having trained **over 6,000 software engineers**, we know what it takes to crack the toughest tech interviews. Since 2014, **Interview Kickstart** alums have been landing lucrative offers from FAANG and Tier-1 tech companies, with an **average salary hike of 49%.** The highest ever offer received by an IK alum is a whopping **$933,000****!**

At IK, you get the unique opportunity to learn from expert instructors who are **hiring managers and tech leads** at Google, Facebook, Apple, and other top Silicon Valley tech companies.

*Want to nail your next tech interview?** Sign up for our **FREE Webinar.*

Here’s what we’ll cover in this article:

- Types of Data Structures
- Array Interview Questions
- Linked Lists Interview Questions
- Stacks Interview Questions
- Queues Interview Questions
- Hash Tables Interview Questions
- Trees Interview Questions
- Heaps Interview Questions
- Graphs Interview Questions
- Data Structures Interview Questions FAQs
- How to Nail Your Next Data Structures Interview

**Types of Data Structures**

There are 8 commonly-used data structures that every programmer must know:

- Arrays
- Linked Lists
- Stacks
- Queues
- Hash Tables
- Trees
- Heaps
- Graphs

**Array Interview Questions**

**What is an Array?**

An array is a fixed-size structure that can hold items of the same data type. An array can be:

- An array of integers
- An array of strings
- An array of arrays

Arrays are indexed, and random access is possible.

**Interview Questions on Arrays**

- Find common elements in three-sorted arrays.
- Find whether a given array contains a subarray with sum equal to zero.
- Find the number of ways you can make change for n cents for a given value ‘n’ if we have an infinite supply of each of S = {s1, s2, … sm} valued coins.
- Find the majority element in a given array of ‘n’ elements. A majority element in an array of size ‘n’ is an element that appears more than n/2 times in the array.
- Given two arrays ‘a1[]’ and ‘a2[]’, find if a2[] is a subset of Trees[].
- Given the daily cost of a stock in an array ‘a[]’ of size ‘n,’ find the days on which you should buy and sell the stock such that your profit is maximized between these days.
- Given an array of size ‘n,’ find the smallest positive integer that cannot be represented as a sum of some elements from the array.
- In a sorted array ‘a[]’ of size ‘n’ and number ‘x,’ find a pair whose sum is closest to x.
- In an unsorted array ‘a’ of size ‘n’ of positive integers, one number a1 from set {1, 2, ...n} is missing, and one number a2 occurs twice in the array. Find these two numbers.
- Write a program to cyclically rotate an array by one.

**Linked Lists Interview Questions**

**What is a Linked List?**

A linked list is a sequential data structure made up of elements linked to each other in linear order. Here, you get sequential access to data. Random access is not possible.

**Interview Questions on Linked Lists **

- How are linked lists more efficient than arrays?
- What is a Doubly Linked List (DLL)? What are its applications?
- Write a program to check if a singly linked list is a palindrome.
- How do you find the middle element of a singly linked list in one pass?
- Write a function to delete a linked list.
- Write a program to delete the middle element of a linked list.
- Write a function to remove the duplicate elements from a sorted linked list.
- Write a function to reverse the nodes of a linked list.
- Write a program to find the ‘nth’ node from the end of a linked list.
- Write a program to check if a given linked list contains a cycle. If so, find the starting node of the cycle.

**Stacks Interview Questions**

**What is a Stack?**

A stack is a Last In First Out (LIFO) data structure, in which the last element is accessed first.

**Interview Questions on Stacks**

- Compare array-based implementation and linked list stack implementation.
- How would you efficiently implement ‘k’ stacks in a single array?
- How would you implement a stack using priority queue or heap?
- Write a program to convert a queue to a stack.
- Write a program to reverse a string using stack.
- Write a program to sort a stack using recursion.
- Write a program to sort a stack using another stack.
- Write a program to check if an array is stack sortable.
- Write a program to delete the middle element of a stack.
- Write a program to reverse a stack without using recursion and extra space.

**Queues Interview Questions**

**What is a Queue?**

A queue is a First In First Out (FIFO) data structure in which the first element is accessed first.

**Interview Questions on Queues **

- What are the benefits of circular queues?
- What is complexity analysis of queue operations?
- Write a program to convert a queue to a stack.
- Write a program to implement a priority queue.
- Write a program to sort a queue without extra space.
- Write a program to implement a queue using only one stack.
- Write a program to implement deque using doubly-linked lists.
- Write a program to reverse only the first ‘k’ elements of a queue.
- Write a program to efficiently implement ‘k’ queues in a single array.

**Hash Tables Interview Questions**

**What is a Hash Table?**

A hash table is a data structure that stores values that have keys associated with each of them.

**Interview Questions on Hash Tables**

- Differentiate between ‘hashing’ and ‘hash tables.’
- Explain how hash tables are implemented.
- What is the complexity of a hash table?
- Write a program to find if a list is cyclic using a hash table.

**Trees Interview Questions**

**What is a Tree?**

A tree is a structure in which data is linked and organized hierarchically. This differs from a linked list in which items are linked in a linear fashion.

**Interview Questions on Trees **

- Write a program to find if two binary trees are identical.
- Write a program to delete a node from a binary search tree.
- Write a program to convert a binary tree into a binary search tree.
- Write a program to find a lowest common ancestor (LCA) of a binary tree.
- Write a program to check if a given binary tree is a subtree of another binary tree.

**Heaps Interview Questions**

**What is a Heap?**

A heap is a type of binary tree in which the values of the parent nodes are compared to that of their children and are arranged accordingly.

**Interview Questions on Heaps**

- Explain a treap data structure.
- Write a program to check if a binary tree is a min-heap.
- Write a program for min heap and max heap implementation.
- Write a program to convert max heap to min heap in linear time.
- Given an array and a positive integer ‘k,’ find the

**Graphs Interview Questions**

**What is a Graph?**

A graph is a data structure consisting of a finite set of vertices or nodes and a set of edges connecting these vertices.

**Interview Questions on Graphs**

- Given ‘A’ and ‘B,’ find all the stepping numbers in the range A to B. A number is called a stepping number if the adjacent digits have a difference of 1.
- Write a program to clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.
- You’re given a directed graph having ‘A’ nodes, a matrix ‘B’ of size ‘M * 2’, which represents the ‘M’ edges such that there is an edge directed from node B[i][0] to node B[i][1]. Find whether the graph contains a cycle or not. Return 1 if a cycle is present, else return 0.
- You’re given an undirected graph having ‘A’ nodes labeled from 1 to A, with ‘M’ edges given in the form of matric B of size M * 2, where (B[i][0], B[i][1]) represents two nodes connected by an edge. Find whether the graph contains a cycle or not. Return 1 if a cycle is present, else return 0.
- You’re given a graph of ‘A’ nodes, weighted edges in the form of array ‘B,’ starting point ‘C,’ a destination ‘D,’ and some extra edges in the form of vector ‘E.’ Find the length of the shortest path from C to D if you can use a maximum of one road from the given roads in E. All roads are one way, i.e., they go from B[i][0] to B[i][1].

**Data Structures Interview Questions FAQs**

- Do all tech coding interviews feature data structure questions?

No, it depends on the company and the role you’re being interviewed for.

- How do you prepare for an interview on data structures?

Practice is the key to cracking data structure interviews. The more you practice, the better you’ll get at solving unseen problems. For more practice problems with solutions, visit the Problems and Learn page.

**How to Nail Data Structure Interview Questions**

If you’re looking for guidance on how to prepare for a tech interview, **join Interview Kickstart. **Our Tech Interview Masterclass is the Best Data Structures and Algorithms Course to Crack FAANG Interviews, covering everything you need to learn to excel at your next tech interview.

As pioneers in the field of technical interview preparation, we have helped **thousands of software engineers** land their dream jobs at Google, Facebook, Apple, Netflix, Amazon, and more!