Top 50 Data Structures Interview Questions 2026
Data Structures and Algorithms (DSA) form the foundation of computer science and are crucial for technical interviews at top tech companies. This comprehensive guide covers the top 50 data structures interview questions that are frequently asked in 2026, from basic concepts to advanced implementations. Once you're solid on data structures, level up with System Design Interview Questions 2026 to tackle architecture problems at Google, Amazon, and other top companies.
Table of Contents
- Arrays & Strings (1-10)
- Linked Lists (11-20)
- Stacks & Queues (21-25)
- Trees & Binary Trees (26-35)
- Graphs (36-40)
- Hash Tables & Heaps (41-45)
- Advanced Data Structures (46-50)
- FAQs
Arrays & Strings (1-10)
Question 1: What is an array? What are its advantages and disadvantages?
Difficulty: Easy
Why interviewers ask this: To test fundamental understanding of the most basic data structure.
An array is a collection of elements stored at contiguous memory locations.
# Array declaration in different languages
# Python
arr = [1, 2, 3, 4, 5]
# Java
int[] arr = {1, 2, 3, 4, 5};
# C++
int arr[5] = {1, 2, 3, 4, 5};
Advantages:
- Random Access: O(1) access time using index
- Cache Friendly: Contiguous memory improves cache performance
- Simple Implementation: Easy to understand and use
Disadvantages:
- Fixed Size: Most languages require specifying size upfront
- Insertion/Deletion Cost: O(n) for shifting elements
- Memory Wastage: If allocated size > actual need
Time Complexity:
| Operation | Time Complexity |
|---|---|
| Access | O(1) |
| Search | O(n) |
| Insertion | O(n) |
| Deletion | O(n) |
Question 2: What is the difference between array and linked list?
Difficulty: Easy
| Feature | Array | Linked List |
|---|---|---|
| Memory | Contiguous | Non-contiguous |
| Size | Fixed (static) | Dynamic (grows/shrinks) |
| Access | Random (O(1)) | Sequential (O(n)) |
| Insertion/Deletion | O(n) (shifting) | O(1) (if position known) |
| Memory Usage | Less overhead | More overhead (pointers) |
| Cache Performance | Better | Worse |
# Array vs Linked List example
# Array insertion (shifting required)
def insert_array(arr, index, value):
# Shift elements to right
for i in range(len(arr)-1, index-1, -1):
arr[i] = arr[i-1]
arr[index] = value
# Linked list insertion (no shifting)
class Node:
def __init__(self, data):
self.data = data
self.next = None
def insert_linked_list(head, position, new_node):
if position == 0:
new_node.next = head
return new_node
current = head
for _ in range(position-1):
current = current.next
new_node.next = current.next
current.next = new_node
return head
Question 3: Reverse an array/string
Difficulty: Easy
# Method 1: Two-pointer approach
def reverse_array(arr):
left, right = 0, len(arr) - 1
while left < right:
arr[left], arr[right] = arr[right], arr[left]
left += 1
right -= 1
return arr
# Method 2: Using slicing (Python)
def reverse_array_slice(arr):
return arr[::-1]
# Method 3: Using built-in function
def reverse_array_builtin(arr):
arr.reverse()
return arr
# Reverse string
def reverse_string(s):
# Convert to list, reverse, join back
chars = list(s)
left, right = 0, len(chars) - 1
while left < right:
chars[left], chars[right] = chars[right], chars[left]
left += 1
right -= 1
return ''.join(chars)
# Test cases
print(reverse_array([1, 2, 3, 4, 5])) # [5, 4, 3, 2, 1]
print(reverse_string("hello")) # "olleh"
Question 4: Find the maximum subarray sum (Kadane's Algorithm)
Difficulty: Medium
def max_subarray_sum(arr):
"""
Kadane's Algorithm: O(n) time, O(1) space
"""
max_ending_here = arr[0]
max_so_far = arr[0]
for i in range(1, len(arr)):
# Either extend previous subarray or start new
max_ending_here = max(arr[i], max_ending_here + arr[i])
max_so_far = max(max_so_far, max_ending_here)
return max_so_far
# Extended version: Also return subarray indices
def max_subarray_sum_with_indices(arr):
max_ending_here = arr[0]
max_so_far = arr[0]
start = end = 0
temp_start = 0
for i in range(1, len(arr)):
if arr[i] > max_ending_here + arr[i]:
max_ending_here = arr[i]
temp_start = i
else:
max_ending_here = max_ending_here + arr[i]
if max_ending_here > max_so_far:
max_so_far = max_ending_here
start = temp_start
end = i
return max_so_far, start, end
# Test cases
arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
print(max_subarray_sum(arr)) # 6 (subarray [4, -1, 2, 1])
Question 5: Find duplicates in an array
Difficulty: Easy
# Method 1: Using hash set (O(n) time, O(n) space)
def find_duplicates_hash(arr):
seen = set()
duplicates = set()
for num in arr:
if num in seen:
duplicates.add(num)
else:
seen.add(num)
return list(duplicates)
# Method 2: Sorting approach (O(n log n) time, O(1) space)
def find_duplicates_sort(arr):
arr.sort()
duplicates = []
for i in range(1, len(arr)):
if arr[i] == arr[i-1] and (i == 1 or arr[i] != arr[i-2]):
duplicates.append(arr[i])
return duplicates
# Method 3: Using array indices (when 1 ≤ arr[i] ≤ n)
def find_duplicates_index(arr):
"""
For array of size n with elements in range [1, n]
"""
duplicates = []
for i in range(len(arr)):
index = abs(arr[i]) - 1
if arr[index] < 0:
duplicates.append(abs(arr[i]))
else:
arr[index] = -arr[index]
# Restore array
for i in range(len(arr)):
arr[i] = abs(arr[i])
return duplicates
# Test cases
print(find_duplicates_hash([1, 2, 3, 1, 3, 6, 6])) # [1, 3, 6]
print(find_duplicates_index([4, 3, 2, 7, 8, 2, 3, 1])) # [2, 3]
Question 6: Rotate an array by k positions
Difficulty: Medium
# Method 1: Using extra array (O(n) time, O(n) space)
def rotate_array_extra(arr, k):
n = len(arr)
k = k % n # Handle k > n
result = [0] * n
for i in range(n):
result[(i + k) % n] = arr[i]
return result
# Method 2: Reverse method (O(n) time, O(1) space)
def rotate_array_reverse(arr, k):
n = len(arr)
k = k % n
# Helper function to reverse array between indices
def reverse(start, end):
while start < end:
arr[start], arr[end] = arr[end], arr[start]
start += 1
end -= 1
# Reverse entire array
reverse(0, n-1)
# Reverse first k elements
reverse(0, k-1)
# Reverse remaining elements
reverse(k, n-1)
return arr
# Method 3: Juggling algorithm (O(n) time, O(1) space)
def rotate_array_juggling(arr, k):
n = len(arr)
k = k % n
# Find GCD of n and k
def gcd(a, b):
while b:
a, b = b, a % b
return a
g = gcd(n, k)
for i in range(g):
temp = arr[i]
j = i
while True:
d = (j + k) % n
if d == i:
break
arr[j] = arr[d]
j = d
arr[j] = temp
return arr
# Test cases
arr = [1, 2, 3, 4, 5, 6, 7]
print(rotate_array_reverse(arr.copy(), 3)) # [5, 6, 7, 1, 2, 3, 4]
Question 7: Implement two-sum problem
Difficulty: Easy
# Problem: Given an array and target, find two numbers that sum to target
# Return their indices
# Method 1: Brute force (O(n²) time, O(1) space)
def two_sum_brute(arr, target):
n = len(arr)
for i in range(n):
for j in range(i+1, n):
if arr[i] + arr[j] == target:
return [i, j]
return []
# Method 2: Using hash map (O(n) time, O(n) space)
def two_sum_hash(arr, target):
num_map = {}
for i, num in enumerate(arr):
complement = target - num
if complement in num_map:
return [num_map[complement], i]
num_map[num] = i
return []
# Method 3: Two-pointer with sorted array (O(n log n) time, O(1) space)
def two_sum_sorted(arr, target):
# Create list of (value, index) pairs
indexed_arr = [(val, idx) for idx, val in enumerate(arr)]
indexed_arr.sort(key=lambda x: x[0])
left, right = 0, len(indexed_arr) - 1
while left < right:
current_sum = indexed_arr[left][0] + indexed_arr[right][0]
if current_sum == target:
return [indexed_arr[left][1], indexed_arr[right][1]]
elif current_sum < target:
left += 1
else:
right -= 1
return []
# Test cases
arr = [2, 7, 11, 15]
target = 9
print(two_sum_hash(arr, target)) # [0, 1] (2 + 7 = 9)
Question 8: Find the majority element (Boyer-Moore Voting Algorithm)
Difficulty: Medium
def majority_element(arr):
"""
Boyer-Moore Voting Algorithm
Returns element that appears more than n/2 times
O(n) time, O(1) space
"""
candidate = None
count = 0
# Phase 1: Find candidate
for num in arr:
if count == 0:
candidate = num
count = 1
elif num == candidate:
count += 1
else:
count -= 1
# Phase 2: Verify candidate
count = 0
for num in arr:
if num == candidate:
count += 1
if count > len(arr) // 2:
return candidate
return None
# Extended version: Find all elements appearing more than n/3 times
def majority_element_ii(arr):
"""
Returns elements that appear more than n/3 times
"""
if not arr:
return []
# Candidates and counts
cand1, cand2 = None, None
count1, count2 = 0, 0
# First pass: Find candidates
for num in arr:
if cand1 == num:
count1 += 1
elif cand2 == num:
count2 += 1
elif count1 == 0:
cand1 = num
count1 = 1
elif count2 == 0:
cand2 = num
count2 = 1
else:
count1 -= 1
count2 -= 1
# Second pass: Verify candidates
count1 = count2 = 0
for num in arr:
if num == cand1:
count1 += 1
elif num == cand2:
count2 += 1
result = []
if count1 > len(arr) // 3:
result.append(cand1)
if count2 > len(arr) // 3:
result.append(cand2)
return result
# Test cases
print(majority_element([3, 2, 3])) # 3
print(majority_element_ii([1, 1, 1, 3, 3, 2, 2, 2])) # [1, 2]
Question 9: Merge two sorted arrays
Difficulty: Easy
# Method 1: Using extra space (O(m+n) time, O(m+n) space)
def merge_sorted_arrays(arr1, arr2):
result = []
i = j = 0
while i < len(arr1) and j < len(arr2):
if arr1[i] <= arr2[j]:
result.append(arr1[i])
i += 1
else:
result.append(arr2[j])
j += 1
# Add remaining elements
result.extend(arr1[i:])
result.extend(arr2[j:])
return result
# Method 2: Merge in-place when arr1 has enough space
def merge_in_place(arr1, m, arr2, n):
"""
arr1 has size m+n with first m elements valid
arr2 has n elements
"""
i = m - 1 # Last valid element in arr1
j = n - 1 # Last element in arr2
k = m + n - 1 # Last position in arr1
while i >= 0 and j >= 0:
if arr1[i] > arr2[j]:
arr1[k] = arr1[i]
i -= 1
else:
arr1[k] = arr2[j]
j -= 1
k -= 1
# Copy remaining elements from arr2
while j >= 0:
arr1[k] = arr2[j]
j -= 1
k -= 1
return arr1
# Test cases
arr1 = [1, 3, 5, 7]
arr2 = [2, 4, 6, 8]
print(merge_sorted_arrays(arr1, arr2)) # [1, 2, 3, 4, 5, 6, 7, 8]
# In-place merge test
arr1_large = [1, 3, 5, 7, 0, 0, 0, 0]
arr2_small = [2, 4, 6, 8]
print(merge_in_place(arr1_large, 4, arr2_small, 4)) # [1, 2, 3, 4, 5, 6, 7, 8]
Question 10: Find missing number in array
Difficulty: Easy
# Problem: Array of size n contains numbers from 0 to n (one missing)
# Find the missing number
# Method 1: Sum formula (O(n) time, O(1) space)
def missing_number_sum(arr):
n = len(arr)
expected_sum = n * (n + 1) // 2
actual_sum = sum(arr)
return expected_sum - actual_sum
# Method 2: XOR approach (O(n) time, O(1) space)
def missing_number_xor(arr):
n = len(arr)
xor_all = 0
# XOR all numbers from 0 to n
for i in range(n + 1):
xor_all ^= i
# XOR all numbers in array
for num in arr:
xor_all ^= num
return xor_all
# Method 3: Cyclic sort (O(n) time, O(1) space)
def missing_number_cyclic(arr):
n = len(arr)
i = 0
while i < n:
correct = arr[i]
if arr[i] < n and arr[i] != arr[correct]:
arr[i], arr[correct] = arr[correct], arr[i]
else:
i += 1
for i in range(n):
if arr[i] != i:
return i
return n
Related Articles
- System Design Interview Questions 2026 � Apply your DSA knowledge to build scalable systems
- Top 50 Java Interview Questions 2026 � Implement DSA solutions in Java for MNC interviews
- Top 50 Python Interview Questions 2026 � Python-based DSA implementations and algorithm questions
- Networking Interview Questions 2026 � Computer networks fundamentals to pair with DSA prep
Last Updated: March 2026 | � 2026 PapersAdda.com
You May Also Like
- Intel Interview Questions 2026 - Round-by-Round Guide
- LG Interview Questions 2026 - Round-by-Round Guide
- EY Interview Questions 2026 - Round-by-Round Guide
- PhonePe Interview Questions 2026 - Round-by-Round Guide
Frequently Asked Questions
What is the placement process for Top 50 Data Structures Interview Questions 2026 (DSA-focused hiring)?
Typically, the process starts with an online coding assessment focused on core DSA concepts like arrays, linked lists, trees, graphs, and hash tables. Shortlisted candidates then move to one or more technical interview rounds where they explain approach, complexity, and edge cases, followed by a final HR round for communication and fit.
What salary range can candidates expect in DSA-focused placements?
Salary varies widely by company tier and your performance in DSA rounds, but DSA-heavy roles often target competitive packages for strong problem-solving ability. For many entry-to-mid level hiring cycles, offers commonly fall within a broad band (e.g., mid to high single digits up to 20+ LPA in top companies), with the final number depending on interview outcomes and prior experience.
What are the eligibility criteria for these DSA interview-based placements?
Most companies expect candidates to have a solid understanding of fundamentals: time/space complexity, recursion, and standard data structures. Eligibility usually includes being in the final year or having relevant internship/project experience, along with the ability to code in at least one language (commonly C++/Java/Python) and solve problems under constraints.
How difficult are the interview questions compared to typical DSA practice?
The difficulty is usually moderate to high because questions are designed to test both correctness and efficiency, not just brute-force coding. Expect a mix of classic patterns (two pointers, sliding window, BFS/DFS, hashing) and questions that require careful handling of edge cases and constraints.
How should I prepare using the Top 50 Data Structures Interview Questions 2026 list?
Start by mastering the most frequently asked categories: arrays/strings, linked lists, trees, graphs, and hash tables, then practice each question with a focus on optimal complexity. For every problem, write down the approach, dry-run on examples, and learn common variations so you can adapt quickly during interviews.
What are the typical interview rounds for DSA placements?
A common structure is: (1) online coding test, (2) technical interview(s) covering DSA and problem-solving, and (3) HR round. In technical rounds, interviewers often ask you to justify your approach, analyze time/space complexity, and discuss how you would handle edge cases or optimize further.
Which topics are most common in DSA interviews for 2026 hiring?
The most common topics include traversal and properties of trees (BST, binary tree traversals), graph algorithms (BFS/DFS, shortest path basics), linked list operations (reversal, cycle detection), and hashing-based problems (frequency counting, collisions handling conceptually). Arrays and strings frequently appear with patterns like two pointers, sliding window, prefix sums, and interval logic.
How do I apply and what selection rate should I expect?
To apply, candidates typically register through the company’s official careers page or the placement portal used by the hiring organization, then complete the coding assessment when invited. Selection rate depends heavily on your coding test performance and consistency in DSA fundamentals; in general, only a small fraction of applicants clear the initial screening, so strong practice and mock tests significantly improve your odds.
Explore this topic cluster
More resources in Interview Questions
Use the category hub to browse similar questions, exam patterns, salary guides, and preparation resources related to this topic.
Paid contributor programme
Sat this this year? Share your story, earn ₹500.
First-person experience reports help future candidates prep smarter. We pay verified contributors ₹500 via UPI per accepted story — with byline.
Submit your story →Ready to practice?
Take a free timed mock test
Put what you learned into practice. Our mock tests match the 2026 pattern with timer, navigator, reveal, and score breakdown. No signup.
Start Free Mock Test →Related Articles
ABB Interview Questions 2026 - Round-by-Round Guide
ABB interviews usually go beyond textbook answers. Panels expect clean thought process, structured communication, and...
Accenture Interview Questions 2026
Accenture is a leading global professional services company providing strategy, consulting, digital, technology, and...
Adobe Interview Questions 2026
Adobe is a multinational computer software company known for its creative, marketing, and document management solutions....
AMD Interview Questions 2026 - Round-by-Round Guide
AMD interviews usually go beyond textbook answers. Panels expect clean thought process, structured communication, and...
Atlassian Interview Questions 2026 - Round-by-Round Guide
Atlassian interviews usually go beyond textbook answers. Panels expect clean thought process, structured communication, and...
More from PapersAdda
How to Prepare for Google Coding Interview 2026
TCS Salary After 3 Years: Growth, Bands & Appraisal Data 2026
Airbnb Placement Papers 2026 – Questions, Answers & Complete Interview Guide
Intel Placement Papers 2026 | Interview Questions & Preparation Guide