/Leetcode-problems

Leetcode problems

Primary LanguageC++

Leetcode problems

Pointer Manipulation (Two pointers)

✅ Medium 167. Two Sum II Two pointers Sorting solution

✅ Medium 15. 3 Sum Two pointers Sorting Hash table solution 🔥

✅ Medium 16. 3Sum Closest Two pointers Sorting solution

✅ Medium 18. 4Sum Two pointers Sorting Backtracking solution

✅ Easy 26. Remove Duplicates from Sorted Array Two pointers solution

✅ Medium 80. Remove Duplicates from Sorted Array II Two pointers Sorting solution 🖕 🖕

✅ Easy 121. Best Time to Buy and Sell Stock Two pointers DP solution 🔥

✅ Medium 122. Best Time to Buy and Sell Stock II Two pointers DP solution

✅ Medium 11. Container With Most Water Two pointers Greedy solution 🔥

✅ Hard 42. Trapping Rain Water Two pointers Dynamic programming Prfix max solution 🖕 🖕

✅ Medium 287. Find the Duplicate Number Two pointers Floyd Cyclic sort solution 🔥 🖕 🖕 🖕

✅ Easy 125. Valid Palindrome Two pointers String solution 🖕

✅ Easy 680. Valid Palindrome II Two pointers String solution

✅ Easy 917. Reverse Only Letters Two pointers String solution

✅ Medqium 5. Longest Palindromic Substring Two pointers String DP solution 🔥

✅ Medium 647. Palindromic Substrings Two pointers String DP solution 🖕

✅ Easy 408. Valid Word Abbreviation Two pointers String solution

✅ Easy 696. Count Binary Substrings Two pointers String solution 🔥 🖕

✅ Easy 88. Merge Sorted Array Two pointers Sorting solution 🖕

✅ Easy 27. Remove Element Two pointers solution

✅ Medium 189. Rotate Array Two pointers solution 🔥 🖕 🖕

✅ Easy 796. Rotate String String solution 🖕

✅ Easy 169. Majority Element Boyer moore Two pointers Sorting Divide & conquer solution 🔥 🖕 🖕

✅ Medium 161. One Edit Distance Two pointers solution 🖕

✅ Medium 443. String Compression Two pointers solution


Pointer Manipulation (sliding window)

✅ Medium 3. Longest Substring Without Repeating Characters Sliding window Hash tablesolution 🔥 🖕 🖕

✅ Medium 159. Longest Substring with At Most Two Distinct Characters Sliding window Hash table solution

✅ Medium 340. Longest Substring with At Most K Distinct Characters Sliding window Hash table solution 🖕

✅ Hard 992. Subarrays with K Different Integers Sliding window Hash table solution 🔥 🖕 🖕 🖕

✅ Medium 1248. Count Number of Nice Subarrays Sliding window Hash table solution

✅ Hard 76. Minimum Window Substring Sliding window Hash table String solution 🔥 🖕 🖕

✅ Medium 209. Minimum Size Subarray Sum Sliding window Prefix sum solution

✅ Medium 424. Longest Repeating Character Replacement Sliding window Hash table String solution 🔥


Binary Search

✅ Easy 704. Binary Search Binary search solution

✅ Easy 35. Search Insert Position Binary search solution

✅ Medium 74. Search a 2D Matrix Binary search solution

✅ Medium 34. Find First and Last Position of Element in Sorted Array Binary search solution 🔥 🖕

✅ Medium 33. Search in Rotated Sorted Array Binary search solution 🖕

✅ Medium 153. Find Minimum in Rotated Sorted Array Binary search Divide & conquer solution 🔥 🖕 🖕 🖕

✅ Medium 162. Find Peak Element Binary search solution 🔥 🖕 🖕

✅ Easy 69. Sqrt(x) Binary search Newton's law Math solution 🔥 🖕

✅ Hard 4. Median of Two Sorted Arrays Binary search solution 😈


Prefix Sum

Two Sum Problem

✅ Medium 560. Subarray Sum Equals K Prefix sum Hash table solution 🔥

✅ Medium 974. Subarray Sums Divisible by K Prefix sum Hash table solution 🔥 🖕

✅ Medium 523. Continuous Subarray Sum Prefix sum Hash table solution 🖕 🖕

✅ Medium 525. Contiguous Array Prefix sum Hash table solution 🔥

Range Sum

✅ Medium 370. Range Addition Prefix sum Sweep line Laze propagtion solution 🖕

✅ Easy 303. Range Sum Query - Immutable Prefix sum solution

✅ Medium 304. Range Sum Query 2D - Immutable Prefix sum Matrix solution 🔥

✅ Medium 238. Product of Array Except Self Prefix sum solution


Sweep line

✅ Easy 252. Meeting Rooms (Leetcode Premium) Interval Sorting solution

✅ Medium 253. Meeting Rooms II (Leetcode Premium) Interval Sorting Two pointer Heap solution 🔥

✅ Medium 56. Merge Intervals Interval Sorting solution

✅ Medium 57. Insert Interval Interval Sorting solution 🔥 🖕 🖕

✅ Medium 1272. Remove Interval Interval Sorting solution 🖕 🖕

✅ Medium 435. Non-overlapping Intervals Interval Sorting Greedy solution 🔥

✅ Medium 1288. Remove Covered Intervals Interval Sorting solution 🔥 🖕

✅ Hard 352. Data Stream as Disjoint Intervals Interval Sorting Binary search Design solution 🖕 🖕 🖕

✅ Medium 986. Interval List Intersections Interval Two pointers Sorting solution 🔥 🖕

✅ Medium 1229. Meeting Scheduler Interval Two pointers Sorting solution

✅ Hard 759. Employee Free Time Interval Sorting Heap solution 🔥 🖕 🖕

✅ Hard 218. The Skyline Problem Interval Sorting Heap solution 🖕 🖕 🖕


Bitwise Operation

✅ Medium 371. Sum of Two Integers Bitwise XOR AND solution

✅ Medium 29. Divide Two Integers Bitwise XOR solution 🖕 🖕

✅ Easy 191. Number of 1 Bits Bitwise AND solution 🖕

✅ Easy 338. Counting Bits Bitwise AND DP solution 🔥 🖕

✅ Easy 268. Missing Number Bitwise XOR Hash table Cyclic sort solution 🔥 🖕

✅ Easy 136. Single Number Bitwise XOR solution

✅ Easy 190. Reverse Bits Bitwise XOR AND solution 🖕


Matrix

✅ Easy 867. Transpose Matrix Matrix solution

✅ Medium 48. Rotate Image Matrix solution 🔥

✅ Medium 73. Set Matrix Zeroes Matrix Hash table solution

✅ Medium 54. Spiral Matrix Matrix solution 🔥 🖕

✅ Medium 59. Spiral Matrix II Matrix solution

✅ Medium 835. Image Overlap Matrix solution 🖕


Data Structure

Hash table

✅ Easy 1. Two Sum Hash table solution

✅ Easy 217. Contains Duplicate Hash table Sorting solution

✅ Medium 128. Longest Consecutive Sequence Hash table Sorting solution 🔥 🖕

✅ Easy 1207. Unique Number of Occurrences Hash table solution

✅ Easy 242. Valid Anagram Hash table Sorting String solution

✅ Medium 49. Group Anagrams Hash table Sorting String solution

✅ Easy 706. Design HashMap Hash table Design solution 🔥

✅ Medium 1570. Dot Product of Two Sparse Vectors Hash table Two pointers Design solution 🔥 🖕

✅ Medium 380. Insert Delete GetRandom O(1) Hash table Design solution 🔥 🖕

✅ Easy 266. Palindrome Permutation Hash table solution

✅ Medium 267. Palindrome Permutation II Hash table Backtracking solution 🖕

Stack / Queue

✅ Easy 20. Valid Parentheses Stack String solution 🔥

✅ Medium 155. Min Stack Stack Design solution 🔥

✅ Easy 225. Implement Stack using Queues Stack Queue Design solution

✅ Easy 232. Implement Queue using Stacks Stack Queue Design solution

✅ Hard 224. Basic Calculator Stack Math solution 🔥

✅ Medium 227. Basic Calculator II Stack Math solution

Monotonic Stack

✅ Easy 496. Next Greater Element I Monotonic stack Hash table solution 🔥

✅ Medium 503. Next Greater Element II Monotonic stack solution

✅ Medium 739. Daily Temperatures Monotonic stack solution

✅ Medium 316. Remove Duplicate Letters Monotonic stack String solution 🔥

✅ Medium 1081. Smallest Subsequence of Distinct Characters Monotonic stack String solution

✅ Medium 402. Remove K Digits Monotonic stack solution

✅ Hard 84. Largest Rectangle in Histogram Monotonic stack solution 🔥

Monotonic Queue

✅ Hard 239. Sliding Window Maximum Monotonic queue Sliding window Deque Heap solution 🔥

✅ Hard 862. Shortest Subarray with Sum at Least K Monotonic queue Sliding window Deque solution 😈


Linked List

✅ Easy 206. Reverse a Linked List Linked list Recursion solution 🖕

✅ Medium 92. Reverse Linked List II Linked list solution 🔥 🖕

✅ Hard 25. Reverse Nodes in k-Group Linked list Recursion solution 🖕

✅ Easy 141. Detect Cycle in a Linked List Linked list Hash table Two pointers solution

✅ Medium 142. Linked List Cycle II Linked list Two pointers solution 🔥

✅ Medium 2. Add Two Numbers Linked list solution

✅ Medium 160. Intersection of Two Linked Lists Linked list solution

✅ Easy 203. Remove Linked List Elements Linked list Recursion solution

✅ Medium 1836. Remove Duplicates From an Unsorted Linked List Linked list Hash table solution 🖕

✅ Medium 19. Remove Nth Node From End Of List Linked list Two pointers solution 🖕

✅ Medium 237. Delete Node in a Linked List Linked list solution 🔥

✅ Easy 876. Middle of the Linked List Linked list Two pointers solution

✅ Medium 2095. Delete the Middle Node of a Linked List Linked list Two pointers solution 🖕

✅ Medium 86. Partition List Linked list Two pointers solution 🖕

✅ Medium 725. Split Linked List in Parts Linked list solution 🔥

✅ Easy 234. Palindrome Linked List Linked list Two pointers solution 🖕

✅ Easy 21. Merge Two Sorted Lists Linked list Recursion solution

✅ Hard 23. Merge K Sorted Lists Linked list Recursion Heap solution 🔥

✅ Medium 143. Reorder List Linked list Two pointers solution 🔥 🖕 🖕

✅ Medium 24. Swap Nodes in Pairs Linked list solution 🔥 🖕

✅ Medium 147. Insertion Sort List Linked list Sorting solution 😈


Graph

DFS, BFS

✅ Easy 1971. Find if Path Exists in Graph Graph DFS BFS solution

✅ Medium 133. Clone Graph Graph DFS BFS Hash table solution 🔥 🖕

✅ Medium 200. Number of Islands Graph DFS BFS Union find solution 🔥

✅ Medium 695. Max Area of Island Graph DFS BFS Union find solution

✅ Easy 463. Island Perimeter Graph DFS BFS solution 🖕

✅ Easy 733. Flood Fill Graph DFS BFS solution

✅ Medium 1162. As Far from Land as Possible Graph BFS solution 🔥 🖕

✅ Medium 841. Keys and Rooms Graph DFS BFS solution

✅ Medium 490. The Maze Graph BFS DFS solution 🔥

✅ Hard 127. Word Ladder Graph BFS Bidirectional solution 🔥 🖕

✅ Medium 399. Evaluate Division Graph DFS BFS solution 🔥 🖕 🖕 🖕

✅ Medium 417. Pacific Atlantic Water Flow Graph DFS BFS Hash table solution 🖕 🖕

✅ Medium 1197. Minimum Knight Moves Graph BFS Hash table solution

Topological Sort

✅ Medium Topological sort - pre-request task arrangment Graph Topological Sort Kahn algorithm

✅ Medium 207. Course Schedule Graph DFS BFS Hash table Topological Sort Kahn algorithm solution

✅ Medium 210. Course Schedule II Graph BFS Topological Sort Kahn algorithm solution 🔥

✅ Hard 269. Alien Dictionary Graph BFS Topological Sort solution 🖕 🖕

✅ Medium 802. Find Eventual Safe States Graph DFS BFS Topological Sort solution 🔥 🖕

Union find

✅ Medium 323. Number of Connected Components in an Undirected Graph Graph DFS Union find solution 🖕

✅ Medium 547. Number of Provinces Graph DFS BFS Union find solution

✅ Medium 684. Redundant Connection Graph DFS Union find solution 🔥

✅ Medium 261. Graph Valid Tree Graph DFS Union find solution 🔥 🖕

Dijkstra's algorithm

✅ Medium Dijkstra's algorithm - find min path Graph Heap BFS Dijkstra's algorithm

✅ Medium 743. Network Delay Time Graph BFS Dijkstra's algorithm solution

✅ Medium 505. The Maze II Graph BFS DFS Dijkstra's algorithm Heap solution 🔥

Others

✅ Medium 1615. Maximal Network Rank Graph solution


Tree

Tree Traversal

✅ Easy 144. Binary Tree Preorder Traversal Tree DFS Stack solution

✅ Easy 94. Binary Tree Inorder Traversal Tree DFS Stack solution

✅ Easy 145. Binary Tree Postorder Traversal Tree DFS Stack solution 🔥 🖕 🖕

✅ Medium 102. Binary Tree Level Order Traversal Tree BFS DFS solution 🔥

✅ Medium 107. Binary Tree Level Order Traversal II Tree BFS DFS solution

✅ Medium 103. Binary Tree Zigzag Level Order Traversal Tree BFS DFS solution

✅ Medium 199. Binary Tree Right Side View Tree BFS DFS solution

✅ Medium 314. Binary Tree Vertical Order Traversal Tree BFS DFS solution 🔥

✅ Hard 987. Vertical Order Traversal of a Binary Tree Tree BFS DFS solution

✅ Medium 545. Boundary of Binary Tree Tree BFS DFS solution 🖕

✅ Medium 116. Populating Next Right Pointers in Each Node Tree BFS DFS solution 🖕

✅ Medium 117. Populating Next Right Pointers in Each Node II Tree BFS DFS solution 🖕

✅ Easy 104. Maximum Depth of Binary Tree Tree DFS BFS solution

✅ Easy 111. Minimum Depth of Binary Tree Tree BFS DFS solution 🔥 🖕

✅ Easy 110. Balanced Binary Tree Tree BFS DFS solution 🔥 🖕 🖕

✅ Easy 226. Invert Binary Tree Tree DFS BFS solution 🔥

✅ Medium 114. Flatten Binary Tree to Linked List Tree DFS BFS solution 🔥 🖕 🖕

✅ Easy Depth List Tree BFS solution

Serialize and Deserialize

✅ Hard 297. Serialize and Deserialize Binary Tree Tree DFS BFS Design solution 🔥 🖕 🖕

✅ Medium 449. Serialize and Deserialize BST Tree DFS BFS Design solution

✅ Medium 1008. Construct Binary Search Tree from Preorder Traversal Tree DFS BFS Design solution

✅ Medium 105. Construct Binary Tree from Preorder and Inorder Traversal Tree DFS Hash table solution 🔥 🖕

✅ Medium 106. Construct Binary Tree from Inorder and Postorder Traversal Tree DFS Hash table solution

✅ Medium 426. Convert Binary Search Tree to Sorted Doubly Linked List Tree DFS Linked list solution 🔥

Binary Search Tree (BST)

✅ Medium 98. Validate Binary Search Tree Tree BST DFS solution 🔥

✅ Easy 700. Search in a Binary Search Tree Tree BST DFS solution

✅ Easy 270. Closest Binary Search Tree Value Tree BST DFS solution 🔥 🖕

✅ Medium 701. Insert into a Binary Search Tree Tree BST DFS solution 🔥 🖕

✅ Medium 450. Delete Node in a BST Tree BST DFS solution 🔥 🖕 🖕

✅ Medium 230. Kth Smallest Element in a BST Tree BST DFS Divide & Conquer solution 🖕

✅ Medium 173. Binary Search Tree Iterator Tree BST DFS Stack Design Iterator solution 🔥 🖕 🖕

✅ Medium 99. Recover Binary Search Tree Tree BST DFS BFS solution 🖕 🖕

✅ Easy 108. Convert Sorted Array to Binary Search Tree Tree BST DFS Divide & Conquer solution 🔥

✅ Medium 1382. Balance a Binary Search Tree Tree BST DFS Divide & Conquer solution

✅ Medium 96. Unique Binary Search Trees Tree BST DP solution

✅ Medium 95. Unique Binary Search Trees II Tree BST DP solution 🖕 🖕

Lowest Common Ancestor (LCA)

✅ Medium 235. Lowest Common Ancestor of BST Tree BST DFS BFS solution 🔥

✅ Medium 236. Lowest Common Ancestor of a Binary Tree Tree DFS solution 🔥

✅ Medium 1644. Lowest Common Ancestor of a Binary Tree II Tree DFS solution 🖕

✅ Medium 1650. Lowest Common Ancestor of a Binary Tree III Tree Hash table solution

✅ Medium 1676. Lowest Common Ancestor of a Binary Tree IV Tree Hash table solution

Pure Recursion / Back Tracking (Message Sending)

✅ Easy 100. Same Tree Tree DFS BFS solution

✅ Easy 101. Symmetric Tree Tree DFS BFS solution 🔥

✅ Easy 572. Subtree of Another Tree Tree DFS BFS solution 🔥 🖕

✅ Easy 257. Binary Tree Paths Tree DFS BFS solution 🔥 🖕

✅ Medium 1448. Count Good Nodes in Binary Tree Tree DFS BFS solution

✅ Easy 112. Path Sum Tree DFS BFS solution

✅ Medium 113. Path Sum II Tree DFS Backtracking solution 🖕

✅ Medium 437. Path Sum III Tree DFS Hash table Prefix sum solution 🖕 🖕 🖕

✅ Medium 129. Sum Root to Leaf Numbers Tree DFS solution 🖕

✅ Medium 814. Binary Tree Pruning Tree DFS solution 🖕 🖕 🖕

✅ Medium 222. Count Complete Tree Nodes Tree DFS solution 🖕

✅ Medium 1120. Maximum Average Subtree Tree DFS solution 🔥 🖕

✅ Hard 124. Binary Tree Maximum Path Sum Tree DFS solution 🔥

Trie

✅ Medium 208. Implement Trie (Prefix Tree) Tree String Design Trie solution

✅ Medium 211. Design Add and Search Words Data Structure Tree String Trie DFS solution 🔥 🖕 🖕


Heap

✅ Hard 23. Merge K Sorted Lists Link list Heap solution

✅ Medium 347. Top K Frequent Elements Hash table Sorting Heap Bucket sort solution 🔥 🖕

✅ Hard 295. Find Median from Data Stream Sorting Heap solution 🔥 🖕 🖕

✅ Medium 215. Kth Largest Element in an Array Sorting Heap Quick select solution 🔥

✅ Hard Merge K Sorted Array Heap solution 🔥


Recursion

✅ Medium 39. Combination Sum Recursion Backtracking solution

✅ Medium 40. Combination Sum II Recursion Backtracking solution 🔥 🖕

✅ Medium 77. Combinations Recursion Backtracking solution

✅ Medium 78. Subsets Recursion Backtracking solution

✅ Medium 90. Subsets II Recursion Backtracking solution 🔥 🖕 🖕

✅ Medium 46. Permutations Recursion Backtracking solution

✅ Medium 47. Permutations II Recursion Backtracking solution 🔥

✅ Medium 22. Generate Parentheses Recursion Backtracking String solution

✅ Medium 79. Word Search Recursion Backtracking Matrix solution

✅ Hard 212. Word Search II Recursion Trie DFS Backtracking solution 🔥 🖕 🖕

✅ Hard 37. Sudoku Solver Recursion Backtracking solution 🔥 🖕 🖕 🖕

✅ Hard 51. N-Queens Recursion Backtracking solution 🔥 🖕

✅ Medium 1239. Maximum Length of a Concatenated String with Unique Characters Recursion Backtracking solution 🖕


Dynamic Programming

1 dimensional DP

✅ Easy 509. Fibonacci Number Recursion Memorization DP solution

✅ Easy 70. Climbing Stairs Recursion Memorization DP solution

✅ Medium 91. Decode Ways Recursion Tree DP solution 🔥 🖕 🖕

✅ Medium 139. Word Break Recursion DP Memorization Hash table Trie solution 🖕 🖕 🖕

✅ Hard 140. Word Break II Hash table Recursion DP Trie solution 🔥

✅ Medium 53. Maximum Subarray DP Greedy solution 🔥 🖕

✅ Medium 152. Maximum Product Subarray DP solution 🔥

✅ Medium 198. House Robber Recursion DP Memorization solution 🔥

✅ Medium 213. House Robber II Recursion Tree DP solution

✅ Medium 300. Longest Increasing Subsequence Recursion DP Memorization Greedy solution 🔥 🖕 🖕 🖕 🖕

✅ Hard 1713. Minimum Operations to Make a Subsequence DP Hash table Greedy Binary search solution

✅ Medium 322. Coin Change Recursion Memorization DP solution 🔥 🖕

✅ Medium 377. Combination Sum IV Recursion DP Memorization solution

2 dimensional DP

✅ Medium 62. Unique Paths Recursion Tree DP solution

✅ Medium 1143. Longest Common Subsequence Recursion DP solution 🔥 🖕

✅ Hard 1312. Minimum Insertion Steps to Make a String Palindrome DP solution 🔥 🖕 🖕 🖕

✅ Medium 516. Longest Palindromic Subsequence DP solution

✅ Medium 97. Interleaving String Recursion Memorization DP solution

✅ Hard 72. Edit Distance Recursion Memorization DP solution

✅ Hard 115. Distinct Subsequences Recursion Memorization DP solution

✅ Hard 10. Regular Expression Matching Recursion Memorization DP solution 🔥 😈 😈

✅ Hard 44. Wildcard Matching Recursion Memorization DP solution

Knapsack Problem

✅ Medium 416. Partition Equal Subset Sum Recursion Memorization DP solution 🔥

✅ Medium 474. Ones and Zeroes Recursion Memorization DP solution

✅ Medium 494. Target Sum Recursion Memorization DP solution


Divide and Conquer

✅ Medium 50. Pow(x, n) Recursion Math Divide & conquer solution


Greedy

✅ Medium 55. Jump Game Greedy Recursion DP Memorization solution 🔥 🖕

✅ Medium 45. Jump Game II Greedy Recursion DP Memorization solution 🖕 🖕

✅ Medium 134. Gas Station Greedy solution 🔥

✅ Hard 135. Candy Greedy solution

✅ Easy 1710. Maximum Units on a Truck Greedy Sorting solution

✅ Medium 2285. Maximum Total Importance of Roads Greedy Sorting Graph solution 🖕

✅ Medium 1578. Minimum Time to Make Rope Colorful Greedy solution 🖕


Other

✅ Medium 6. Zigzag Conversion string solution

✅ Medium 7. Reverse Integer Math solution

✅ Easy 9. Palindrome Number Math solution

✅ Medium 324. Wiggle Sort II Sorting Quick select solution

✅ Medium 274. H-Index Sorting Quick select solution

✅ Medium 118. Pascal's Triangle Array solution

✅ Medium 119. Pascal's Triangle II Array solution

✅ Easy 263. Ugly Number Math solution

✅ Medium 264. Ugly Number II Math DP solution