0% found this document useful (0 votes)
11 views20 pages

Data Structures Coding Questions - Topic Wise

Uploaded by

tnshr.yadav
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views20 pages

Data Structures Coding Questions - Topic Wise

Uploaded by

tnshr.yadav
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Common Coding Questions - Data Structures (Topic Wise)

Legend
⭐ Must Do - Very Important for Interviews

🟢 Easy

🟡 Medium

🔴 Hard

1. Arrays

Basic Operations

1. ⭐🟢 Find the largest and smallest element in an array

2. ⭐🟢 Reverse an array

3. ⭐🟢 Rotate array by K positions (left/right)

4. 🟢 Find the second largest element

5. 🟢 Remove duplicates from sorted array

6. 🟢 Move all zeros to end

7. 🟢 Union and Intersection of two sorted arrays

Searching & Sorting

8. ⭐🟢 Linear Search and Binary Search

9. 🟢 Find missing number in array (1 to N)

10. 🟢 Find the duplicate in array of N+1 integers

11. 🟡 Search in Rotated Sorted Array

12. 🟡 Find First and Last Position of Element in Sorted Array

13. 🟡 Search a 2D Matrix

Subarray Problems

14. ⭐🟡 Maximum Subarray Sum (Kadane's Algorithm)


15. ⭐🟡 Subarray with Given Sum (Positive numbers)

16. 🟡 Longest Subarray with Sum K

17. 🟡 Subarray with 0 Sum

18. 🔴 Maximum Product Subarray

19. 🔴 Longest Substring Without Repeating Characters

Two Pointer Technique

20. ⭐🟢 Two Sum (Find pair with given sum)

21. 🟡 Three Sum (Find triplets with sum = 0)

22. 🟡 Four Sum

23. 🟡 Container With Most Water

24. 🟡 Remove Duplicates from Sorted Array II

25. 🟡 Sort Colors (Dutch National Flag)

Sliding Window

26. ⭐🟡 Maximum Sum Subarray of Size K

27. 🟡 Longest Substring with K Unique Characters

28. 🟡 Minimum Window Substring

29. 🔴 Sliding Window Maximum

Matrix Problems

30. 🟢 Spiral Matrix Traversal

31. 🟡 Rotate Image/Matrix by 90 degrees

32. 🟡 Set Matrix Zeros

33. 🟡 Search in a Row-Column Sorted Matrix

34. 🔴 Median in Row-Wise Sorted Matrix

Others

35. ⭐🟡 Merge Two Sorted Arrays

36. ⭐🟡 Find Majority Element (Boyer-Moore Voting)


37. 🟡 Next Permutation

38. 🟡 Stock Buy and Sell (Multiple transactions)

39. 🟡 Trapping Rain Water

40. 🔴 Median of Two Sorted Arrays

2. Strings

Basic Operations

41. ⭐🟢 Reverse a String

42. ⭐🟢 Check if string is Palindrome

43. 🟢 Check if two strings are Anagrams

44. 🟢 Remove duplicates from string

45. 🟢 Check if strings are rotations of each other

46. 🟢 Count vowels and consonants

Pattern Matching

47. ⭐🟡 Implement strStr() / Find Needle in Haystack

48. 🟡 KMP Algorithm for Pattern Matching

49. 🔴 Rabin-Karp Algorithm

Subsequence/Substring

50. ⭐🟡 Longest Common Subsequence (LCS)

51. ⭐🟡 Longest Common Substring

52. 🟡 Longest Palindromic Substring

53. 🟡 Longest Repeating Subsequence

54. 🔴 Distinct Subsequences

String Manipulation

55. 🟢 Valid Parentheses

56. 🟢 Roman to Integer / Integer to Roman


57. 🟡 Group Anagrams

58. 🟡 Minimum Characters to Make Palindrome

59. 🟡 String to Integer (atoi)

60. 🟡 Longest Valid Parentheses

Others

61. ⭐🟡 Print all permutations of a string

62. 🟡 Edit Distance (Levenshtein Distance)

63. 🟡 Wildcard Pattern Matching

64. 🔴 Regular Expression Matching

65. 🔴 Count and Say

3. Linked Lists

Basic Operations

66. ⭐🟢 Reverse a Linked List (Iterative and Recursive)

67. ⭐🟢 Detect Cycle in Linked List (Floyd's Algorithm)

68. ⭐🟢 Find Middle of Linked List

69. 🟢 Delete a Node in Linked List

70. 🟢 Search an element in Linked List

71. 🟢 Find Length of Linked List

72. 🟢 Insert Node at Beginning/End/Position

Two Pointer Problems

73. ⭐🟡 Find the Starting Point of Cycle

74. ⭐🟡 Remove Nth Node From End

75. 🟡 Check if Linked List is Palindrome

76. 🟡 Intersection Point of Two Linked Lists

Merging & Sorting


77. ⭐🟡 Merge Two Sorted Linked Lists

78. 🟡 Merge K Sorted Linked Lists

79. 🟡 Sort Linked List (Merge Sort)

80. 🟡 Sort Linked List (Quick Sort)

Advanced Problems

81. 🟡 Add Two Numbers represented by Linked Lists

82. 🟡 Flatten a Multilevel Doubly Linked List

83. 🟡 Clone a Linked List with Random Pointer

84. 🟡 Reverse Nodes in K-Group

85. 🔴 LRU Cache Implementation

Doubly Linked List

86. 🟢 Insert/Delete in Doubly Linked List

87. 🟡 Reverse a Doubly Linked List

88. 🟡 Find pairs with given sum in DLL

4. Stacks

Basic Operations

89. ⭐🟢 Implement Stack using Array

90. ⭐🟢 Implement Stack using Linked List

91. 🟢 Implement two stacks in an array

92. 🟡 Implement Stack using Queue

93. 🟡 Implement Queue using Stack

Stack Problems

94. ⭐🟢 Valid Parentheses / Balanced Brackets

95. ⭐🟡 Next Greater Element


96. 🟡 Next Smaller Element

97. 🟡 Stock Span Problem

98. 🟡 Largest Rectangle in Histogram

99. 🟡 Maximal Rectangle

Expression Problems

100. 🟡 Infix to Postfix Conversion

101. 🟡 Infix to Prefix Conversion

102. 🟡 Postfix Evaluation

103. 🟡 Prefix Evaluation

Others

104. ⭐🟡 Min Stack (Get Min in O(1))

105. 🟡 Sort a Stack

106. 🟡 Reverse a Stack using Recursion

107. 🟡 Remove Duplicate Letters

108. 🔴 Trapping Rain Water using Stack

5. Queues

Basic Operations

109. ⭐🟢 Implement Queue using Array

110. ⭐🟢 Implement Queue using Linked List

111. 🟢 Implement Circular Queue

112. 🟡 Implement Deque (Double-ended Queue)

113. 🟡 Implement Queue using Stack

Queue Problems

114. 🟢 Reverse a Queue

115. 🟡 First Negative Integer in Every Window of Size K


116. 🟡 Generate Binary Numbers from 1 to N

117. 🟡 Implement Stack using Queue

118. 🔴 Sliding Window Maximum (using Deque)

Priority Queue Problems

119. 🟡 K Closest Points to Origin

120. 🟡 Kth Largest Element in Array

121. 🟡 Top K Frequent Elements

122. 🔴 Merge K Sorted Lists

6. Trees (Binary Trees & BST)

Tree Traversals

123. ⭐🟢 Inorder Traversal (Recursive & Iterative)

124. ⭐🟢 Preorder Traversal (Recursive & Iterative)

125. ⭐🟢 Postorder Traversal (Recursive & Iterative)

126. ⭐🟢 Level Order Traversal (BFS)

127. 🟡 Zigzag Level Order Traversal

128. 🟡 Vertical Order Traversal

129. 🟡 Boundary Traversal

130. 🟡 Diagonal Traversal

Tree Properties

131. ⭐🟢 Height/Depth of Binary Tree

132. ⭐🟢 Diameter of Binary Tree

133. 🟢 Count Number of Nodes

134. 🟢 Sum of all Nodes

135. 🟢 Check if two trees are identical

136. 🟡 Check if tree is Balanced


137. 🟡 Check if tree is Symmetric/Mirror

Binary Search Tree

138. ⭐🟢 Search in BST

139. ⭐🟢 Insert in BST

140. ⭐🟢 Delete in BST

141. ⭐🟢 Validate BST

142. 🟡 Kth Smallest Element in BST

143. 🟡 Kth Largest Element in BST

144. 🟡 Lowest Common Ancestor in BST

145. 🟡 Inorder Successor in BST

146. 🟡 Inorder Predecessor in BST

Tree Construction

147. ⭐🟡 Construct Binary Tree from Inorder and Preorder

148. 🟡 Construct Binary Tree from Inorder and Postorder

149. 🟡 Convert Sorted Array to BST

150. 🟡 Flatten Binary Tree to Linked List

Path Problems

151. ⭐🟡 Root to Leaf Paths

152. ⭐🟡 Maximum Path Sum

153. 🟡 Path Sum (Check if sum exists)

154. 🟡 All Paths with Given Sum

155. 🔴 Binary Tree Maximum Path Sum

Others

156. ⭐🟡 Lowest Common Ancestor (LCA)

157. 🟡 Top View of Binary Tree

158. 🟡 Bottom View of Binary Tree


159. 🟡 Left View of Binary Tree

160. 🟡 Right View of Binary Tree

161. 🟡 Connect Nodes at Same Level

162. 🟡 Serialize and Deserialize Binary Tree

163. 🔴 Morris Traversal (Inorder without Stack)

7. Graphs

Graph Representation

164. ⭐🟢 Adjacency Matrix Representation

165. ⭐🟢 Adjacency List Representation

Graph Traversals

166. ⭐🟢 BFS (Breadth First Search)

167. ⭐🟢 DFS (Depth First Search)

168. 🟢 Count Connected Components

169. 🟡 DFS on 2D Matrix/Grid

Cycle Detection

170. ⭐🟡 Detect Cycle in Undirected Graph

171. ⭐🟡 Detect Cycle in Directed Graph

172. 🟡 Detect Cycle using Union-Find

Shortest Path

173. ⭐🟡 Dijkstra's Algorithm (Shortest Path)

174. 🟡 Bellman-Ford Algorithm

175. 🔴 Floyd-Warshall Algorithm (All Pairs Shortest Path)

Topological Sort

176. ⭐🟡 Topological Sort (DFS)


177. ⭐🟡 Topological Sort (Kahn's Algorithm - BFS)

178. 🟡 Course Schedule Problem

179. 🟡 Alien Dictionary

Minimum Spanning Tree

180. 🟡 Prim's Algorithm

181. 🟡 Kruskal's Algorithm

Graph Coloring & Others

182. 🟡 Bipartite Graph Check

183. 🟡 Number of Islands

184. 🟡 Flood Fill Algorithm

185. 🟡 Surrounded Regions

186. 🟡 Word Ladder

187. 🔴 Strongly Connected Components (Kosaraju/Tarjan)

188. 🔴 Bridges in Graph

189. 🔴 Articulation Points

8. Hashing

HashMap/HashSet Problems

190. ⭐🟢 Two Sum using HashMap

191. 🟢 First Non-Repeating Character

192. 🟢 Find All Duplicates in Array

193. 🟡 Group Anagrams using HashMap

194. 🟡 Longest Consecutive Sequence

195. 🟡 Subarray Sum Equals K

196. 🟡 Count Distinct Elements in Window


Frequency Problems

197. ⭐🟢 Count Frequency of Array Elements

198. 🟡 Top K Frequent Elements

199. 🟡 Sort Array by Frequency

200. 🟡 First Element occurring K times

Others

201. 🟡 4 Sum II

202. 🟡 Longest Substring Without Repeating Characters

203. 🟡 Find Itinerary from Tickets

204. 🔴 LRU Cache using HashMap + DLL

9. Heaps (Priority Queue)

Basic Heap Operations

205. ⭐🟢 Implement Min Heap

206. ⭐🟢 Implement Max Heap

207. 🟢 Heap Sort

208. 🟡 Convert Min Heap to Max Heap

K-based Problems

209. ⭐🟡 Kth Largest Element in Array

210. ⭐🟡 Kth Smallest Element in Array

211. 🟡 K Closest Points to Origin

212. 🟡 Top K Frequent Elements

213. 🟡 K Closest Numbers

214. 🔴 Find Median from Data Stream


Merge Problems

215. ⭐🟡 Merge K Sorted Lists

216. 🟡 Merge K Sorted Arrays

217. 🔴 Smallest Range Covering Elements from K Lists

Others

218. 🟡 Connect N Ropes with Minimum Cost

219. 🟡 Task Scheduler

220. 🔴 IPO (Maximum Capital)

10. Dynamic Programming

Classic DP Problems

221. ⭐🟢 Fibonacci Number (Top-Down & Bottom-Up)

222. ⭐🟡 Climbing Stairs

223. ⭐🟡 0/1 Knapsack Problem

224. ⭐🟡 Longest Common Subsequence (LCS)

225. ⭐🟡 Longest Increasing Subsequence (LIS)

226. ⭐🟡 Edit Distance

227. ⭐🟡 Coin Change Problem

228. 🟡 Coin Change 2 (Count Ways)

229. 🟡 Unbounded Knapsack

Grid/Matrix DP

230. ⭐🟡 Unique Paths in Grid

231. 🟡 Unique Paths II (with Obstacles)

232. 🟡 Minimum Path Sum in Grid

233. 🟡 Maximum Path Sum in Grid

234. 🔴 Dungeon Game


Substring/Subsequence

235. ⭐🟡 Longest Palindromic Subsequence

236. ⭐🟡 Longest Palindromic Substring

237. 🟡 Palindrome Partitioning

238. 🟡 Count Palindromic Substrings

239. 🔴 Minimum Insertions to Make Palindrome

Partition Problems

240. 🟡 Partition Equal Subset Sum

241. 🟡 Minimum Subset Sum Difference

242. 🔴 Count of Subset Sum

String DP

243. 🟡 Wildcard Pattern Matching

244. 🔴 Regular Expression Matching

245. 🟡 Distinct Subsequences

246. 🔴 Interleaving String

Stock Problems

247. 🟡 Best Time to Buy and Sell Stock

248. 🟡 Best Time to Buy and Sell Stock II (Multiple transactions)

249. 🔴 Best Time to Buy and Sell Stock III (At most 2 transactions)

250. 🔴 Best Time to Buy and Sell Stock IV (At most K transactions)

251. 🔴 Best Time to Buy and Sell Stock with Cooldown

Others

252. ⭐🟡 House Robber

253. 🟡 House Robber II (Circular)

254. 🟡 Maximum Product Subarray


255. 🟡 Decode Ways

256. 🟡 Word Break

257. 🔴 Word Break II

258. 🔴 Burst Balloons

259. 🔴 Egg Dropping Problem

260. 🔴 Matrix Chain Multiplication

11. Sorting & Searching

Sorting Algorithms

261. ⭐🟢 Bubble Sort

262. ⭐🟢 Selection Sort

263. ⭐🟢 Insertion Sort

264. ⭐🟡 Merge Sort

265. ⭐🟡 Quick Sort

266. 🟡 Heap Sort

267. 🟡 Counting Sort

268. 🟡 Radix Sort

Binary Search Variants

269. ⭐🟢 Binary Search (Iterative & Recursive)

270. ⭐🟡 Find First and Last Occurrence

271. 🟡 Count Occurrences of Element

272. 🟡 Search in Rotated Sorted Array

273. 🟡 Find Minimum in Rotated Sorted Array

274. 🟡 Find Peak Element

275. 🟡 Square Root using Binary Search

276. 🔴 Median of Two Sorted Arrays

Search in 2D
277. 🟡 Search a 2D Matrix

278. 🟡 Search in Row-Column Sorted Matrix

Others

279. 🟡 Aggressive Cows (Binary Search on Answer)

280. 🟡 Book Allocation Problem

281. 🔴 Painter's Partition Problem

12. Backtracking

Permutation & Combination

282. ⭐🟡 Generate all Permutations

283. ⭐🟡 Generate all Subsets/Power Set

284. 🟡 Combination Sum

285. 🟡 Combination Sum II

286. 🟡 Letter Combinations of Phone Number

287. 🟡 Generate Parentheses

Grid/Matrix Problems

288. ⭐🟡 Rat in a Maze

289. ⭐🟡 N-Queens Problem

290. 🟡 Sudoku Solver

291. 🟡 Word Search in Matrix

292. 🔴 Word Search II

Others

293. 🟡 Palindrome Partitioning

294. 🟡 Restore IP Addresses

295. 🔴 Remove Invalid Parentheses


296. 🔴 Expression Add Operators

13. Greedy Algorithms

Basic Greedy

297. ⭐🟢 Activity Selection Problem

298. ⭐🟡 Fractional Knapsack

299. 🟡 Job Sequencing Problem

300. 🟡 Minimum Platforms Required

Interval Problems

301. 🟡 Merge Intervals

302. 🟡 Insert Interval

303. 🟡 Non-overlapping Intervals

304. 🟡 Meeting Rooms

Others

305. 🟡 Jump Game

306. 🟡 Jump Game II

307. 🟡 Gas Station

308. 🟡 Candy Distribution

309. 🔴 Minimum Number of Arrows to Burst Balloons

14. Bit Manipulation

Basic Operations

310. ⭐🟢 Check if number is Power of 2

311. ⭐🟢 Count Set Bits (Brian Kernighan's Algorithm)

312. 🟢 Find the only non-repeating element


313. 🟢 Swap two numbers without temp

314. 🟢 Check if ith bit is set

XOR Problems

315. ⭐🟡 Single Number (Find unique element)

316. 🟡 Single Number II (one element once, rest thrice)

317. 🟡 Single Number III (two unique elements)

318. 🟡 Find XOR from L to R

Others

319. 🟡 Power Set using Bit Manipulation

320. 🟡 Gray Code

321. 🔴 Maximum XOR of Two Numbers

322. 🔴 Count Total Set Bits from 1 to N

15. Trie (Prefix Tree)


323. ⭐🟡 Implement Trie (Insert, Search, StartsWith)

324. 🟡 Longest Common Prefix using Trie

325. 🟡 Word Search II (using Trie)

326. 🔴 Maximum XOR of Two Numbers using Trie

327. 🔴 Design Search Autocomplete System

16. Disjoint Set Union (Union-Find)


328. ⭐🟡 Implement Union-Find with Path Compression

329. 🟡 Number of Connected Components

330. 🟡 Detect Cycle in Undirected Graph

331. 🟡 Redundant Connection

332. 🔴 Accounts Merge


17. Segment Tree / Fenwick Tree (Advanced)
333. 🔴 Range Sum Query (Mutable)

334. 🔴 Range Minimum Query

335. 🔴 Count of Smaller Numbers After Self

18. Mathematical Problems


336. ⭐🟢 Check if Prime Number

337. ⭐🟢 GCD (Greatest Common Divisor)

338. ⭐🟢 LCM (Least Common Multiple)

339. 🟢 Sieve of Eratosthenes (Prime numbers up to N)

340. 🟢 Prime Factorization

341. 🟢 Factorial of Large Number

342. 🟡 Power (x^n) - Efficient calculation

343. 🟡 Palindrome Number

344. 🟡 Reverse Integer

345. 🟡 Excel Sheet Column Number

346. 🔴 Ugly Number II

347. 🔴 Super Pow

19. Matrix/2D Array


348. 🟢 Matrix Multiplication

349. 🟢 Transpose of Matrix

350. 🟡 Rotate Matrix 90 degrees

351. 🟡 Spiral Matrix Print

352. 🟡 Search in Row-Column Sorted Matrix


353. 🟡 Kth Smallest Element in Sorted Matrix

354. 🔴 Median in Row-Wise Sorted Matrix

Study Tips for Interview Preparation:

Priority Order:

1. Start with ⭐ Must Do questions

2. Master 🟢 Easy problems first

3. Move to 🟡 Medium problems

4. Attempt 🔴 Hard problems later

Practice Strategy:

Solve at least 2-3 problems daily

Focus on understanding patterns, not memorizing

Implement solutions in your preferred language

Practice explaining your approach (important for interviews)

Time yourself while solving

Company-wise Focus:

FAANG/Top Tech: All topics, especially DP, Graphs, Trees

Product-based: Arrays, Strings, Trees, DP

Service-based: Basic DS questions, Arrays, Strings, Sorting

Recommended Platforms:

LeetCode

GeeksforGeeks

HackerRank

CodeChef

Codeforces
InterviewBit

Total Questions: 354+

Remember: Understanding the approach and pattern is more important than memorizing solutions!

You might also like