Data structures & algorithms
DSA problems with solutions
545 problems by topic, each with the approach, complexity and a free code runner. Free on DeVert Campus.
Open the practice workspace
Trees (67)
- 104. Height of a Binary TreeEasy
- 105. Level Order Traversal of a Binary TreeEasy
- 106. Diameter of a Binary TreeMedium
- 107. Mirror a Binary TreeMedium
- 108. Inorder Traversal of a Binary TreeEasy
- 109. Preorder Traversal of a Binary TreeEasy
- 110. Postorder Traversal of a Binary TreeEasy
- 111. Check if Two Binary Trees Are IdenticalEasy
- 112. Left View of a Binary TreeMedium
- 113. Right View of a Binary TreeMedium
- 114. Top View of a Binary TreeMedium
- 115. Bottom View of a Binary TreeMedium
- 116. Zig-Zag Level Order TraversalMedium
- 117. Check if a Binary Tree Is Height-BalancedMedium
- 118. Lowest Common Ancestor in a Binary TreeMedium
- 119. Maximum Root-to-Leaf Path SumMedium
- 120. Construct a Binary Tree From Inorder and Preorder Traversals, Print Its PostorderMedium
- 121. Check if a Binary Tree Is SymmetricMedium
- 122. Maximum Width of a Binary TreeMedium
- 123. Count Leaf Nodes in a Binary TreeEasy
- 124. Insert a Node Into a Binary Search TreeEasy
- 125. Delete a Node From a Binary Search TreeMedium
- 126. Find the Minimum and Maximum Value in a BSTEasy
- 127. Find the Inorder Successor of a Node in a BSTMedium
- 128. Check if a Binary Tree Is a Valid BSTMedium
- 129. Find the Lowest Common Ancestor of Two Nodes in a BSTMedium
- 130. Construct a BST From a Preorder TraversalMedium
- 131. Convert a Sorted Array Into a Height-Balanced BSTMedium
- 132. Merge Two BSTs Into OneMedium
- 133. Find the Kth Smallest Element in a BSTMedium
- 134. Find the Closest Value to a Target in a BSTMedium
- 135. Find a Pair With a Given Sum in a BSTMedium
- 407. Reverse Level Order TraversalEasy
- 408. Diagonal Traversal of a Binary TreeMedium
- 409. Boundary Traversal of a Binary TreeMedium
- 410. Construct a Binary Tree From a Bracket-Representation StringMedium
- 411. Convert a Binary Tree Into a Doubly Linked ListMedium
- 412. Convert a Binary Tree Into a Sum TreeMedium
- 413. Minimum Swaps to Convert a Binary Tree Into a BSTHard
- 414. Check if a Binary Tree Is a Sum TreeMedium
- 415. Check if All Leaf Nodes Are at the Same LevelEasy
- 416. Check for Duplicate Subtrees of Size 2 or MoreMedium
- 417. Check if Two Binary Trees Are Mirrors of Each OtherEasy
- 418. Sum of Nodes on the Longest Root-to-Leaf PathMedium
- 419. Check if a Given Graph Is a TreeMedium
- 420. Find the Largest Subtree Sum in a Binary TreeMedium
- 421. Maximum Sum of Non-Adjacent Nodes in a Binary TreeHard
- 422. Print All K-Sum Paths in a Binary TreeHard
- 423. Distance Between Two Nodes in a Binary TreeMedium
- 424. Kth Ancestor of a Node in a Binary TreeMedium
- 425. Find All Duplicate Subtrees in a Binary TreeHard
- 426. Tree Isomorphism ProblemMedium
- 427. Find a Value in a BSTEasy
- 428. Find the Inorder Predecessor of a Node in a BSTMedium
- 429. Populate the Inorder Successor of Every Node in a BSTMedium
- 430. Convert a Binary Tree Into a BSTHard
- 431. Convert a BST Into a Balanced BSTMedium
- 432. Find the Kth Largest Element in a BSTMedium
- 433. Count Pairs From Two BSTs Whose Sum Equals a Given ValueMedium
- 434. Find the Median of a BSTMedium
- 435. Count BST Nodes in a Given RangeEasy
- 436. Replace Every Element With the Least Greater Element on Its RightHard
- 437. Find All Conflicting AppointmentsHard
- 438. Check if a Given Sequence Could Be a Valid BST PreorderMedium
- 439. Check Whether a BST Contains a Dead EndMedium
- 440. Find the Largest BST Subtree in a Binary TreeHard
- 441. Flatten a BST to a Sorted (Right-Skewed) ListMedium
Dynamic Programming (54)
- 80. Maximum Sum Such That No Two Elements Are AdjacentMedium
- 203. 0/1 Knapsack ProblemMedium
- 204. Coin Change - Minimum Number of CoinsMedium
- 205. Coin Change - Count Number of WaysMedium
- 206. Longest Increasing SubsequenceMedium
- 207. Longest Common SubstringMedium
- 208. Matrix Chain Multiplication - Minimum CostHard
- 209. Minimum Cost Path in a GridMedium
- 210. Egg Dropping ProblemHard
- 211. Partition a Set Into Two Subsets With Minimum Difference of SumsMedium
- 212. Rod Cutting ProblemMedium
- 213. Maximum Size Square Sub-Matrix With All 1sMedium
- 214. Climbing Stairs - Count WaysEasy
- 215. Longest Bitonic SubsequenceMedium
- 216. Shortest Common Supersequence LengthMedium
- 217. Wildcard Pattern MatchingHard
- 302. Binomial Coefficient ProblemEasy
- 303. Permutation Coefficient ProblemEasy
- 304. Program for nth Catalan NumberEasy
- 305. Friends Pairing ProblemMedium
- 306. Gold Mine ProblemMedium
- 307. Assembly Line Scheduling ProblemHard
- 308. Painting the Fence ProblemMedium
- 309. Maximize The Cut SegmentsMedium
- 310. LCS of Three StringsMedium
- 311. Maximum Sum Increasing SubsequenceMedium
- 312. Count All Subsequences Having Product Less Than KMedium
- 313. Longest Subsequence With Adjacent Elements Differing by OneMedium
- 314. Maximum Subsequence Sum With No Three Consecutive ElementsMedium
- 315. Maximum Length Chain of PairsMedium
- 316. Maximum Sum of Pairs With Specific DifferenceMedium
- 317. Maximum Difference of Zeros and Ones in a Binary StringMedium
- 318. Minimum Cost to Fill a Bag With Given WeightMedium
- 319. Minimum Removals From Array to Make Max Minus Min At Most KMedium
- 320. Count Ways to Reach a Given Score in a GameEasy
- 321. Count Balanced Binary Trees of Height hHard
- 322. Smallest Sum Contiguous SubarrayEasy
- 323. Unbounded Knapsack (Repetition of Items Allowed)Medium
- 324. Largest Independent Set in a Binary TreeHard
- 325. Longest Palindromic SubsequenceMedium
- 326. Longest Alternating SubsequenceMedium
- 327. Weighted Job SchedulingHard
- 328. Coin Game Winner Where Every Player Has Three ChoicesMedium
- 329. Count DerangementsMedium
- 330. Optimal Strategy for a GameHard
- 331. Optimal Binary Search TreeHard
- 332. Palindrome Partitioning Problem (Minimum Cuts)Hard
- 333. Mobile Numeric Keypad ProblemMedium
- 334. Boolean Parenthesization ProblemHard
- 335. Largest Rectangular Sub-Matrix Whose Sum Is 0Hard
- 336. Largest Area Rectangular Sub-Matrix With Equal Number of 1s and 0sHard
- 337. Maximum Sum Rectangle in a 2D MatrixHard
- 338. Maximum Profit With At Most K TransactionsHard
- 354. The Double Helix - Maximum Sum Path Between Two SequencesHard
Arrays (52)
- 1. Two SumEasy
- 2. Reverse the ArrayEasy
- 3. Find the Maximum and Minimum Element in an ArrayEasy
- 4. Kth Max and Min Element of an ArrayMedium
- 5. Sort an Array of 0s, 1s and 2sEasy
- 6. Move All Negative Elements to One SideEasy
- 7. Union and Intersection of Two Sorted ArraysMedium
- 8. Cyclically Rotate an Array by OneEasy
- 9. Largest Sum Contiguous Subarray (Kadane's Algorithm)Medium
- 10. Minimise the Maximum Difference Between HeightsHard
- 11. Minimum Number of Jumps to Reach End of ArrayMedium
- 12. Find Duplicate in an Array of N+1 IntegersMedium
- 13. Merge Two Sorted Arrays (Combined Sorted Output)Easy
- 14. Merge IntervalsMedium
- 15. Next PermutationMedium
- 16. Count Inversions in an ArrayMedium
- 17. Best Time to Buy and Sell StockEasy
- 18. Find All Pairs With a Given SumEasy
- 19. Find Common Elements in 3 Sorted ArraysMedium
- 20. Rearrange Array in Alternating Positive and Negative ItemsMedium
- 21. Find if There Is a Subarray With Sum Equal to 0Medium
- 22. Find Factorial of a Large NumberMedium
- 23. Find Maximum Product SubarrayMedium
- 24. Find Longest Consecutive SubsequenceMedium
- 25. Elements Appearing More Than N/K TimesHard
- 26. Maximum Profit by Buying and Selling a Share at Most TwiceHard
- 27. Check if an Array Is a Subset of Another ArrayEasy
- 28. Find the Triplet That Sums to a Given ValueMedium
- 29. Trapping Rain WaterMedium
- 30. Chocolate Distribution ProblemMedium
- 31. Smallest Subarray With Sum Greater Than a Given ValueMedium
- 32. Three-Way Partitioning of an Array Around a Given ValueMedium
- 33. Minimum Swaps to Bring Elements Less Than or Equal to K TogetherHard
- 34. Minimum Operations to Make an Array PalindromeHard
- 35. Median of Two Sorted ArraysHard
- 36. Spiral Traversal of a MatrixMedium
- 37. Search an Element in a Row-Wise and Column-Wise Sorted MatrixMedium
- 38. Find Median in a Row-Wise Sorted MatrixMedium
- 39. Find the Row With Maximum Number of 1sMedium
- 40. Print Elements in Sorted Order Using a Row-and-Column-Wise Sorted MatrixEasy
- 41. Maximum Size Rectangle of 1s in a Binary MatrixHard
- 42. Find a Specific Pair in a MatrixHard
- 43. Rotate a Matrix by 90 DegreesMedium
- 44. Kth Smallest Element in a Row-Wise and Column-Wise Sorted MatrixHard
- 45. Common Elements in All Rows of a MatrixMedium
- 76. Find the Repeating and the Missing NumberMedium
- 77. Find the Majority ElementEasy
- 81. Count Triplets Such That One Element Is the Sum of the Other TwoMedium
- 341. Searching in an Array Where Adjacent Differ by at Most KMedium
- 342. Count Triplets With Sum Smaller Than a Given ValueMedium
- 343. Product Array PuzzleMedium
- 356. Rasta and Kheshtak - Biggest Common SubsquareHard
Graphs (45)
- 181. BFS Traversal of a GraphEasy
- 182. DFS Traversal of a GraphEasy
- 183. Detect a Cycle in an Undirected GraphMedium
- 184. Detect a Cycle in a Directed GraphMedium
- 185. Topological Sort of a Directed Acyclic GraphMedium
- 186. Count Connected Components in an Undirected GraphEasy
- 187. Number of Islands in a 2D GridMedium
- 188. Check if a Graph Is BipartiteMedium
- 189. Dijkstra's Shortest Path From a SourceMedium
- 190. Bellman-Ford - Detect a Negative-Weight CycleHard
- 191. Minimum Spanning Tree WeightMedium
- 192. Count Strongly Connected ComponentsHard
- 193. Minimum Steps for a Knight to Reach a Target SquareMedium
- 194. Flood Fill AlgorithmEasy
- 195. Rotten Oranges - Minimum Time for All to RotMedium
- 377. Create a Graph and Print Its Adjacency ListEasy
- 378. Search in a MazeMedium
- 379. Clone a GraphMedium
- 380. Making Wired ConnectionsMedium
- 381. Word Ladder - Shortest Transformation LengthHard
- 382. Minimum Time for Each Job in a DAGMedium
- 383. Course Schedule - Possible to Finish All TasksMedium
- 384. Alien Dictionary - Order of CharactersHard
- 385. Kruskal's Algorithm - MST EdgesMedium
- 386. Prim's Algorithm - MST EdgesMedium
- 387. Total Number of Spanning Trees in a GraphHard
- 388. Bellman-Ford - Shortest Paths From a SourceMedium
- 389. Floyd-Warshall - All-Pairs Shortest PathsMedium
- 390. Travelling Salesman ProblemHard
- 391. Graph Colouring - Minimum Number of ColoursHard
- 392. M-Colouring ProblemMedium
- 393. Snake and Ladder - Minimum Dice ThrowsMedium
- 394. Find Bridges in a GraphHard
- 395. Longest Path in a Directed Acyclic GraphMedium
- 396. Journey to the MoonMedium
- 397. Cheapest Flights Within K StopsMedium
- 398. Oliver and the GameHard
- 399. Water Jug Problem Using BFSMedium
- 400. Minimum Edges to Reverse for a Source-to-Destination PathHard
- 401. Seven Bridges - Eulerian Path ExistenceMedium
- 402. Vertex Cover ProblemHard
- 403. Chinese Postman (Route Inspection) ProblemHard
- 404. Number of Triangles in a Directed and Undirected GraphMedium
- 405. Two Clique ProblemHard
- 406. Minimise the Cash Flow Among a Set of FriendsMedium
Strings (40)
- 46. Reverse a StringEasy
- 47. Check Whether a String Is a PalindromeEasy
- 48. Find Duplicate Characters in a StringEasy
- 49. Check if a String Is a Rotation of Another StringEasy
- 50. Check if a String Is a Valid Shuffle of Two Other StringsMedium
- 51. Count and Say SequenceMedium
- 52. Longest Palindromic SubstringMedium
- 53. Longest Repeating SubsequenceMedium
- 54. Print All Distinct Subsequences of a StringMedium
- 55. Print All Permutations of a StringMedium
- 56. Split a Binary String Into Maximum Number of Balanced SubstringsMedium
- 57. Word Wrap ProblemHard
- 58. Edit DistanceMedium
- 59. Next Greater Number With the Same Set of DigitsMedium
- 60. Balanced Parenthesis CheckerEasy
- 61. Word Break ProblemMedium
- 62. Rabin-Karp Pattern SearchMedium
- 63. KMP Pattern SearchMedium
- 64. Minimum Bracket Reversals to Balance an ExpressionMedium
- 65. Count Palindromic Subsequences in a StringHard
- 66. Longest Common PrefixEasy
- 67. Minimum Swaps for Bracket BalancingMedium
- 68. Longest Common SubsequenceMedium
- 69. Roman Numeral to IntegerEasy
- 70. Recursively Remove Adjacent Duplicate CharactersMedium
- 71. Group Anagrams TogetherMedium
- 72. Minimum Characters to Add at the Front to Make a String PalindromeMedium
- 230. Rearrange a String So That No Two Adjacent Characters Are the SameMedium
- 231. Generate All Valid IP Addresses from a String of DigitsMedium
- 232. Smallest Window Containing All Distinct Characters of a StringMedium
- 233. Smallest Window in a String Containing All Characters of Another StringHard
- 234. Number of Flips to Make a Binary String AlternatingEasy
- 235. Find the First Repeated Word in a StringEasy
- 236. Search a Word in a 2D Grid of CharactersMedium
- 237. Count Occurrences of a Given String in a 2D Character ArrayMedium
- 238. Convert a Sentence to Its Mobile Numeric Keypad SequenceEasy
- 239. Number of Customers Who Could Not Get a ComputerMedium
- 240. Transform One String to Another Using Minimum Number of Given OperationHard
- 241. Check if Two Strings Are IsomorphicEasy
- 242. Print All Sentences from a List of Word ListsMedium
Linked List (35)
- 89. Reverse a Linked ListEasy
- 90. Reverse a Linked List in Groups of Size KMedium
- 91. Detect a Loop in a Linked ListMedium
- 92. Find the Length of the Loop in a Linked ListMedium
- 93. Find the Middle of a Linked ListEasy
- 94. Merge Two Sorted Linked ListsEasy
- 95. Find the Nth Node From the End of a Linked ListEasy
- 96. Check if a Linked List Is a PalindromeMedium
- 97. Rotate a Linked List by N NodesMedium
- 98. Segregate 0s, 1s, and 2s in a Linked ListMedium
- 99. Segregate Even and Odd Nodes in a Linked ListMedium
- 100. Delete Nodes Which Have a Greater Value on the Right SideMedium
- 101. Merge K Sorted Linked ListsMedium
- 102. Add Two Numbers Represented by Linked ListsMedium
- 103. Remove Duplicates From a Sorted Linked ListEasy
- 243. Delete Loop in a Linked ListMedium
- 244. Find the Starting Point of the Loop in a Linked ListMedium
- 245. Remove Duplicates From an Unsorted Linked ListMedium
- 246. Move the Last Element to the Front of a Linked ListEasy
- 247. Add 1 to a Number Represented as a Linked ListMedium
- 248. Intersection of Two Sorted Linked ListsEasy
- 249. Merge Sort on a Linked ListMedium
- 250. Quicksort on a Linked ListMedium
- 251. Check if a Linked List Is CircularEasy
- 252. Split a Circular Linked List Into Two HalvesMedium
- 253. Deletion From a Circular Linked ListMedium
- 254. Reverse a Doubly Linked ListEasy
- 255. Find Pairs With a Given Sum in a Doubly Linked ListMedium
- 256. Count Triplets in a Sorted Doubly Linked List With a Given SumHard
- 258. Sort a K-Sorted Doubly Linked ListMedium
- 259. Rotate a Doubly Linked List by N NodesMedium
- 261. Rotate a Doubly Linked List in Groups of Given SizeHard
- 262. Flatten a Linked ListHard
- 264. Multiply Two Numbers Represented by Linked ListsHard
- 267. Find the First Non-Repeating Character From a Stream of CharactersMedium
Greedy (31)
- 136. Activity Selection ProblemMedium
- 137. Job Sequencing ProblemMedium
- 138. Fractional Knapsack ProblemMedium
- 139. Minimum Number of Platforms Required for a Railway StationMedium
- 140. Minimum and Maximum Amount to Buy All N CandiesMedium
- 141. Maximum Product Subset of an ArrayMedium
- 142. Maximize Array Sum After K NegationsMedium
- 143. Maximize Sum of arr[i] * i After RearrangingMedium
- 144. Minimum Sum of Absolute Differences of Pairs of Two ArraysMedium
- 145. Shortest Job First (SJF) CPU Scheduling - Average Waiting TimeMedium
- 146. LRU Page Replacement - Count Page FaultsMedium
- 147. Smallest Number With Given Number of Digits and Digit SumMedium
- 358. Huffman Coding - Total Encoded LengthMedium
- 359. Water Connection ProblemMedium
- 360. Greedy Algorithm to Find Minimum Number of CoinsEasy
- 361. Maximum Trains for Which Stoppage Can Be ProvidedMedium
- 362. Buy Maximum Stocks if i Stocks Can Be Bought on the i-th DayMedium
- 363. Minimize Cash Flow Among FriendsHard
- 364. Minimum Cost to Cut a Board Into SquaresHard
- 365. Check if It Is Possible to Survive on the IslandHard
- 366. Find Maximum Meetings in One RoomMedium
- 367. Maximum Sum of Absolute Difference of an ArrayMedium
- 368. Maximize Sum of Consecutive Differences in a Circular ArrayMedium
- 369. Smallest Subset With Sum Greater Than All Other ElementsEasy
- 370. Defense of a KingdomHard
- 371. Wine Trading in GergoviaEasy
- 372. K Centers ProblemHard
- 373. Minimum Cost of RopesMedium
- 374. Rearrange Characters in a String Such That No Two Adjacent Are SameMedium
- 375. Maximum Sum Possible With Equal Sum of Three StacksMedium
- 376. Arranging AmplifiersHard
Binary Search (25)
- 73. Find First and Last Position of an Element in a Sorted ArrayMedium
- 74. Search in a Rotated Sorted ArrayMedium
- 75. Integer Square RootEasy
- 85. Find a Peak Element in an ArrayMedium
- 86. Book Allocation ProblemHard
- 87. Painter's Partition ProblemHard
- 88. Aggressive Cows ProblemHard
- 339. Find a Fixed Point in an ArrayMedium
- 340. Optimum Location of a Point to Minimize Total DistanceHard
- 346. Find the Pivot Element in a Sorted Rotated ArrayMedium
- 347. K-th Element of Two Sorted ArraysHard
- 348. Missing Number in an Arithmetic ProgressionEasy
- 349. Smallest Number With at Least N Trailing Zeroes in FactorialMedium
- 352. Eko - Cutting Wood to Get at Least M MetresMedium
- 353. Roti Prata - Minimum Time to Cook P PratasHard
- 355. Bishu and SoldiersMedium
- 357. Kth Smallest Element in a RangeMedium
- Median of a Row-Wise Sorted MatrixHard
- Median of Two Sorted ArraysHard
- Minimum Eating Speed to Finish All Fruit Piles in TimeMedium
- Minimum Ship Capacity to Deliver Packages Within D DaysMedium
- Search in a Row-and-Column Sorted 2D MatrixMedium
- Search Insert Position in a Sorted ArrayEasy
- Single Element in a Sorted Duplicate ArrayEasy
- Smallest Divisor With a Given Sum ThresholdMedium
Queue (22)
- 168. Reverse the First K Elements of a QueueMedium
- 169. Interleave the First Half of a Queue With the Second HalfMedium
- 257. Simulate a QueueEasy
- 276. Implement n Queues in a Single ArrayHard
- 278. Implement a Circular QueueEasy
- 280. LRU Cache ImplementationHard
- 282. Reverse a Queue Using RecursionEasy
- 284. Find the First Circular Tour That Visits All Petrol PumpsMedium
- 285. First Negative Integer in Every Window of Size KMedium
- 286. Distance of Nearest Cell Having 1 in a Binary MatrixMedium
- 287. Sum of Minimum and Maximum Elements of All Subarrays of Size KMedium
- 288. Minimum Sum of Squares of Character Counts After Removing K CharactersMedium
- 289. First Non-Repeating Character in a StreamMedium
- 291. Check if All Levels of Two Binary Trees Are AnagramsMedium
- Check if a Queue Can Be Sorted Using an Auxiliary StackEasy
- Generate Binary Numbers from 1 to N Using a QueueEasy
- Implement a Queue Using Two StacksEasy
- Minimum Time to Rot All Oranges in a GridMedium
- Shortest Path in a Binary MazeMedium
- Shortest Subarray With Sum At Least KHard
- Sliding Window Maximum Using a DequeMedium
- Task Scheduler With CooldownMedium
Backtracking (21)
- 148. N-Queens - Count SolutionsHard
- 149. Rat in a Maze - Count Distinct PathsMedium
- 150. Solve a Sudoku PuzzleHard
- 151. M-Coloring ProblemMedium
- 152. Subset Sum ProblemMedium
- 153. Combination Sum - Count CombinationsMedium
- 154. Maximum Number Possible With At Most K SwapsMedium
- 155. Count Palindromic Partitions of a StringMedium
- 156. Generate All Valid Parentheses CombinationsMedium
- 157. Word Break - Count All WaysHard
- 292. Print All N-Queens SolutionsHard
- 293. Remove Invalid ParenthesesHard
- 294. Print All Palindromic Partitions of a StringMedium
- 295. Tug of WarMedium
- 296. Find Shortest Safe Route in a Path With LandminesMedium
- 297. Path of More Than K Length From a SourceMedium
- 298. Longest Possible Route in a Matrix With HurdlesMedium
- 299. Print All Possible Paths From Top Left to Bottom Right of a MatrixMedium
- 300. Partition of a Set Into K Subsets With Equal SumHard
- 301. Find the K-th Permutation SequenceMedium
- 350. Subset SumsMedium
Bit Manipulation (21)
- 218. Count Set Bits in an IntegerEasy
- 219. Find the Two Non-Repeating Elements in an ArrayMedium
- 220. Count Bits to Flip to Convert A to BEasy
- 221. Count Total Set Bits From 1 to NMedium
- 222. Check if a Number Is a Power of 2Easy
- 223. Find the Position of the Only Set BitEasy
- 224. Divide Two Integers Without Using *, /, or %Medium
- 225. Calculate the Square of a Number Without Using *, /, or pow()Easy
- 226. Find XOR of All Numbers From L to RMedium
- 227. Find the Element That Appears Once (All Others Appear Exactly Three Times)Medium
- 229. Copy Set Bits in a RangeEasy
- Add Two Integers Without Using + or -Easy
- Bitwise AND of All Numbers in a RangeMedium
- Check if Two Integers Differ by Exactly One BitEasy
- Clear the Rightmost Set BitEasy
- Count Subsets With a Given XOR ValueMedium
- Generate All Subsets of a Set Using BitmaskingMedium
- Generate the Full n-bit Gray Code SequenceMedium
- Maximum XOR of Two Numbers in an ArrayHard
- Swap Two Bits at Given PositionsEasy
- Total Hamming Distance Across an ArrayHard
Stack (19)
- 158. Simulate a StackEasy
- 159. Min Stack - Support getMin in O(1)Medium
- 160. Next Greater Element for Every Array ElementMedium
- 161. Sort a Stack Using RecursionMedium
- 162. Largest Rectangular Area in a HistogramHard
- 163. Longest Valid Parentheses SubstringHard
- 164. Check for Redundant Brackets in an ExpressionMedium
- 165. Stock Span ProblemMedium
- 166. The Celebrity ProblemMedium
- 167. Iterative Tower of Hanoi - Minimum Number of MovesEasy
- 170. Find the Middle Element of a StackEasy
- 260. Implement Two Stacks in One ArrayMedium
- 263. Implement N Stacks in a Single ArrayHard
- 266. Arithmetic Expression EvaluationHard
- 268. Evaluation of a Postfix ExpressionMedium
- 270. Insert an Element at the Bottom of a StackMedium
- 272. Reverse a Stack Using RecursionMedium
- 274. Check if an Array Is a Stack Permutation of AnotherMedium
- 290. Next Smaller Element for Every Array ElementMedium
Heap (19)
- 171. Kth Largest Element in an ArrayMedium
- 172. Kth Smallest Element in an ArrayMedium
- 173. Sort a Nearly Sorted (K-Sorted) ArrayMedium
- 174. Merge K Sorted ArraysMedium
- 175. Find the Running Median of a Stream of IntegersHard
- 176. Check if a Binary Tree Is a Valid HeapMedium
- 177. Minimum Cost to Connect N RopesMedium
- 178. Find the K Largest Elements in an ArrayMedium
- 179. K Closest Points to the OriginMedium
- 180. Top K Frequent ElementsMedium
- 265. Sort an Array Using Heap SortMedium
- 269. Maximum of All Subarrays of Size KMedium
- 271. Merge Two Binary Max-HeapsMedium
- 273. Kth Largest Sum Among All Contiguous SubarraysMedium
- 275. Reorganize a String So No Two Adjacent Characters RepeatMedium
- 277. Smallest Range Covering Elements From K ListsHard
- 279. Convert a BST to a Min-HeapMedium
- 281. Convert a Min-Heap to a Max-HeapMedium
- 283. Minimum Sum of Two Numbers Formed From Digits of an ArrayMedium
Sorting (15)
- 83. Merge SortMedium
- 84. Quick SortMedium
- 344. Sort an Array According to Count of Set BitsEasy
- 345. Minimum Number of Swaps Required to Sort an ArrayMedium
- 351. Merge Sort - In-Place MergeHard
- Count Inversions in an ArrayHard
- Height CheckerEasy
- Largest Number Formed From ArrayMedium
- Merge Overlapping IntervalsMedium
- Minimum Number of Platforms RequiredHard
- Radix Sort for Non-Negative IntegersEasy
- Relative Sort ArrayMedium
- Sort a Nearly Sorted (K-Sorted) ArrayMedium
- Sort an Array of 0s, 1s, and 2s (Dutch National Flag)Easy
- Sort Characters By FrequencyEasy
Hashing (13)
- 78. Find a Pair With a Given DifferenceMedium
- 79. Find Four Elements That Sum to a Given ValueHard
- 82. Count Subarrays With Sum ZeroMedium
- Anagram CheckEasy
- First Non-Repeating CharacterEasy
- Group AnagramsMedium
- Isomorphic StringsMedium
- Longest Consecutive SequenceMedium
- Longest Subarray With Equal Number of 0s and 1sMedium
- Longest Subarray With Sum KMedium
- Longest Substring With At Most K Distinct CharactersHard
- Majority ElementEasy
- Two Sum - Return IndicesEasy
Math (12)
- Binomial Coefficient Modulo a PrimeMedium
- Chinese Remainder TheoremHard
- Count Primes in RangeMedium
- Digital RootEasy
- GCD and LCM of Two NumbersEasy
- Modular ExponentiationMedium
- Modular Multiplicative InverseMedium
- Palindrome Number CheckEasy
- Perfect Number CheckEasy
- Prime Factorization with ExponentsMedium
- Prime Number CheckEasy
- Sum of Euler's Totient FunctionHard
Recursion (12)
- Check if a String is a Palindrome Using RecursionEasy
- Count Ways to Climb a StaircaseMedium
- Factorial of NEasy
- Generate All Permutations of a StringMedium
- Josephus Problem - Find the WinnerMedium
- N-Queens CountHard
- Print All Subsequences of a StringMedium
- Recursive Linear Search in an ArrayEasy
- Reverse a String Using RecursionEasy
- Sum of Digits of a NumberEasy
- Tower of Hanoi Move SequenceMedium
- Word Break - Count Ways to Segment a StringHard
Two Pointer (12)
- Container With Most WaterMedium
- Merge Two Sorted Arrays In PlaceMedium
- Move Zeroes to the EndEasy
- Pair with Target Sum in Sorted ArrayEasy
- Quadruplets Summing to TargetHard
- Remove Duplicates from Sorted Array In-PlaceEasy
- Sort an Array of Three ColorsMedium
- Squares of a Sorted ArrayMedium
- Three Sum Closest to TargetMedium
- Trapping Rain WaterHard
- Triplets Summing to ZeroMedium
- Valid Palindrome Ignoring PunctuationEasy
Sliding Window (12)
- Count Anagram SubstringsMedium
- First Negative Integer in Every Window of Size KEasy
- Longest Subarray of 1s After Flipping At Most K ZerosMedium
- Longest Substring with At Most K Distinct CharactersMedium
- Longest Substring Without Repeating CharactersMedium
- Maximum Average Subarray of Size KEasy
- Maximum Number of Vowels in a Substring of Length KEasy
- Maximum Points from CardsMedium
- Maximum Sum Subarray of Size KEasy
- Minimum Window SubstringHard
- Sliding Window MaximumHard
- Smallest Subarray with Sum at Least TargetMedium
Searching (10)
- Efficient Search Using Exponential SearchMedium
- Elements Appearing More Than n/3 TimesMedium
- Find the Missing Number in a SequenceEasy
- First and Last Occurrence of a TargetEasy
- Jump Search on a Sorted ArrayEasy
- Kth Smallest Element in a Row-Wise and Column-Wise Sorted MatrixHard
- Majority Element FinderEasy
- Peak Index in a Mountain Array via Ternary SearchMedium
- Search in a Sorted 2D Matrix (Staircase Search)Medium
- Smallest Range Covering Elements from K Sorted ListsHard
Trie (8)
- 196. Implement a Trie - Insert and Search WordsMedium
- 197. Find the Shortest Unique Prefix for Every WordHard
- 198. Phone Directory - Autocomplete by PrefixMedium
- 199. Print Unique Rows in a Boolean MatrixMedium
- 200. Maximum XOR of Two Numbers in an ArrayHard
- 201. Count Distinct Substrings of a StringMedium
- 202. Count Words With a Given PrefixEasy
- 228. Word Break - Print All Sentences (Trie)Hard