LeetCode Solutions

LeetCode is an online platform that provides a collection of coding challenges to help programmers and software engineers improve their coding skills and prepare for technical interviews. It covers a wide range of topics in computer science, including data structures, algorithms, databases, shell scripting, and more.


  1. Two Sum
  2. Palindrome Number
  3. Roman to Integer
  4. Longest Common Prefix
  5. Valid Parentheses
  6. Merge Two Sorted Lists
  7. Remove Duplicates from Sorted Array
  8. Remove Element
  9. Search Insert Position
  10. Length of Last Word
  11. Add Binary
  12. Sqrt(x)
  13. Climbing Stairs
  14. Remove Duplicates from Sorted List
  15. Merge Sorted Array
  16. Binary Tree Inorder Traversal
  17. Same Tree
  18. Symmetric Tree
  19. Maximum Depth of Binary Tree
  20. Convert Sorted Array to Binary Search Tree
  21. Plus One
  22. Balanced Binary Tree
  23. Minimum Depth of Binary Tree
  24. Path Sum
  25. Pascal’s Triangle
  26. Pascal’s Triangle II
  27. Best Time to Buy and Sell Stock
  28. Valid Palindrome
  29. Single Number
  30. Linked List Cycle
  31. Binary Tree Preorder Traversal
  32. Binary Tree Postorder Traversal
  33. Intersection of Two Linked Lists
  34. Excel Sheet Column Title
  35. Majority Element
  36. Excel Sheet Column Number
  37. Reverse Bits
  38. Number of 1 Bits
  39. Happy Number
  40. Remove Linked List Elements
  41. Isomorphic Strings
  42. Reverse Linked List
  43. Contains Duplicate
  44. Contains Duplicate II
  45. Implement Stack using Queues
  46. Invert Binary Tree
  47. Summary Ranges
  48. Power of Two
  49. Implement Queue using Stacks
  50. Palindrome Linked List
  51. Valid Anagram
  52. Binary Tree Paths
  53. Add Digits
  54. Ugly Number
  55. Missing Number
  56. First Bad Version
  57. Move Zeroes
  58. Word Pattern
  59. Nim Game
  60. Range Sum Query – Immutable
  61. Power of Three
  62. Counting Bits
  63. Power of Four
  64. Reverse String
  65. Reverse Vowels of a String
  66. Intersection of Two Arrays
  67. Intersection of Two Arrays II
  68. Valid Perfect Square
  69. Guess Number Higher or Lower
  70. Ransom Note
  71. First Unique Character in a String
  72. Find the Difference
  73. Is Subsequence
  74. Binary Watch
  75. Sum of Left Leaves
  76. Convert a Number to Hexadecimal
  77. Longest Palindrome
  78. Fizz Buzz
  79. Third Maximum Number
  80. Add Strings
  81. Number of Segments in a String
  82. Arranging Coins
  83. Find All Numbers Disappeared in an Array
  84. Assign Cookies
  85. Repeated Substring Pattern
  86. Hamming Distance
  87. Island Perimeter
  88. Number Complement
  89. License Key Formatting
  90. Max Consecutive Ones
  91. Construct the Rectangle
  92. Teemo Attacking
  93. Next Greater Element I
  94. Keyboard Row
  95. Find Mode in Binary Search Tree
  96. Base 7
  97. Relative Ranks
  98. Perfect Number
  99. Fibonacci Number
  100. Detect Capital
  101. Longest Uncommon Subsequence I
  102. Minimum Absolute Difference in BST
  103. Reverse String II
  104. Diameter of Binary Tree
  105. Student Attendance Record I
  106. Reverse Words in a String III
  107. Maximum Depth of N-ary Tree
  108. Array Partition
  109. Binary Tree Tilt
  110. Reshape the Matrix
  111. Subtree of Another Tree
  112. Distribute Candies
  113. N-ary Tree Preorder Traversal
  114. N-ary Tree Postorder Traversal
  115. Longest Harmonious Subsequence
  116. Range Addition II
  117. Minimum Index Sum of Two Lists
  118. Can Place Flowers
  119. Merge Two Binary Trees
  120. Maximum Product of Three Numbers
  121. Average of Levels in Binary Tree
  122. Maximum Average Subarray I
  123. Set Mismatch
  124. Two Sum IV – Input is a BST
  125. Robot Return to Origin
  126. Image Smoother
  127. Second Minimum Node In a Binary Tree
  128. Longest Continuous Increasing Subsequence
  129. Valid Palindrome II
  130. Baseball Game
  131. Binary Number with Alternating Bits
  132. Count Binary Substrings
  133. Degree of an Array
  134. Search in a Binary Search Tree
  135. Kth Largest Element in a Stream
  136. Design HashSet
  137. Design HashMap
  138. To Lower Case
  139. 1-bit and 2-bit Characters
  140. Find Pivot Index
  141. Self Dividing Numbers
  142. Flood Fill
  143. Find Smallest Letter Greater Than Target
  144. Min Cost Climbing Stairs
  145. Largest Number At Least Twice of Others
  146. Shortest Completing Word
  147. Prime Number of Set Bits in Binary Representation
  148. Toeplitz Matrix
  149. Jewels and Stones
  150. Minimum Distance Between BST Nodes
  151. Rotate String
  152. Unique Morse Code Words
  153. Number of Lines To Write String
  154. Largest Triangle Area
  155. Most Common Word
  156. Shortest Distance to a Character
  157. Goat Latin
  158. Positions of Large Groups
  159. Flipping an Image
  160. Rectangle Overlap
  161. Backspace String Compare
  162. Buddy Strings
  163. Lemonade Change
  164. Transpose Matrix
  165. Binary Gap
  166. Leaf-Similar Trees
  167. Middle of the Linked List
  168. Projection Area of 3D Shapes
  169. Uncommon Words from Two Sentences
  170. Fair Candy Swap
  171. Surface Area of 3D Shapes
  172. Monotonic Array
  173. Increasing Order Search Tree
  174. Sort Array By Parity
  175. Smallest Range I
  176. Reverse Only Letters
  177. Sort Array By Parity II
  178. Long Pressed Name
  179. Unique Email Addresses
  180. Number of Recent Calls
  181. Range Sum of BST
  182. Valid Mountain Array
  183. DI String Match
  184. Delete Columns to Make Sorted
  185. Verifying an Alien Dictionary
  186. N-Repeated Element in Size 2N Array
  187. Univalued Binary Tree
  188. Largest Perimeter Triangle
  189. Squares of a Sorted Array
  190. Add to Array-Form of Integer
  191. Cousins in Binary Tree
  192. Find the Town Judge
  193. Available Captures for Rook
  194. Find Common Characters
  195. Maximize Sum Of Array After K Negations
  196. Complement of Base 10 Integer
  197. Partition Array Into Three Parts With Equal Sum
  198. Binary Prefix Divisible By 5
  199. Remove Outermost Parentheses
  200. Sum of Root To Leaf Binary Numbers
  201. Divisor Game
  202. Matrix Cells in Distance Order
  203. Valid Boomerang
  204. Last Stone Weight
  205. Remove All Adjacent Duplicates In String
  206. Height Checker
  207. Greatest Common Divisor of Strings
  208. Occurrences After Bigram
  209. Duplicate Zeros
  210. Distribute Candies to People
  211. Defanging an IP Address
  212. Relative Sort Array
  213. Number of Equivalent Domino Pairs
  214. N-th Tribonacci Number
  215. Find Words That Can Be Formed by Characters
  216. Distance Between Bus Stops
  217. Day of the Week
  218. Maximum Number of Balloons
  219. Unique Number of Occurrences
  220. Minimum Cost to Move Chips to The Same Position
  221. Split a String in Balanced Strings
  222. Check If It Is a Straight Line
  223. Cells with Odd Values in a Matrix
  224. Minimum Time Visiting All Points
  225. Find Winner on a Tic Tac Toe Game
  226. Subtract the Product and Sum of Digits of an Integer
  227. Element Appearing More Than 25% In Sorted Array
  228. Convert Binary Number in a Linked List to Integer
  229. Find Numbers with Even Number of Digits
  230. Replace Elements with Greatest Element on Right Side
  231. Find N Unique Integers Sum up to Zero
  232. Decrypt String from Alphabet to Integer Mapping
  233. Decompress Run-Length Encoded List
  234. Convert Integer to the Sum of Two No-Zero Integers
  235. Maximum 69 Number
  236. Rank Transform of an Array
  237. Remove Palindromic Subsequences
  238. The K Weakest Rows in a Matrix
  239. Number of Steps to Reduce a Number to Zero
  240. Check If N and Its Double Exist
  241. Count Negative Numbers in a Sorted Matrix
  242. Sort Integers by The Number of 1 Bits
  243. How Many Numbers Are Smaller Than the Current Number
  244. Increasing Decreasing String
  245. Find a Corresponding Node of a Binary Tree in a Clone of That Tree
  246. Lucky Numbers in a Matrix
  247. Find the Distance Value Between Two Arrays
  248. Create Target Array in the Given Order
  249. Find Lucky Integer in an Array
  250. Count Largest Group
  251. Minimum Subsequence in Non-Increasing Order
  252. String Matching in an Array
  253. Minimum Value to Get Positive Step by Step Sum
  254. Reformat The String
  255. Maximum Score After Splitting a String
  256. Kids With the Greatest Number of Candies
  257. Destination City
  258. Check If All 1’s Are at Least Length K Places Away
  259. Consecutive Characters
  260. Number of Students Doing Homework at a Given Time
  261. Check If a Word Occurs As a Prefix of Any Word in a Sentence
  262. Make Two Arrays Equal by Reversing Subarrays
  263. Maximum Product of Two Elements in an Array
  264. Shuffle the Array
  265. Final Prices With a Special Discount in a Shop
  266. Running Sum of 1d Array
  267. XOR Operation in an Array
  268. Average Salary Excluding the Minimum and Maximum Salary
  269. Path Crossing
  270. Can Make Arithmetic Progression From Sequence
  271. Number of Good Pairs
  272. Water Bottles
  273. Count Odd Numbers in an Interval Range
  274. Count Good Triplets
  275. Kth Missing Positive Number
  276. Make The String Great
  277. Three Consecutive Odds
  278. Thousand Separator
  279. Most Visited Sector in a Circular Track
  280. Detect Pattern of Length M Repeated K or More Times
  281. Matrix Diagonal Sum
  282. Replace All ?’s to Avoid Consecutive Repeating Characters
  283. Special Positions in a Binary Matrix
  284. Sum of All Odd Length Subarrays
  285. Rearrange Spaces Between Words
  286. Crawler Log Folder
  287. Design Parking System
  288. Special Array With X Elements Greater Than or Equal X
  289. Maximum Nesting Depth of the Parentheses
  290. Mean of Array After Removing Some Elements
  291. Largest Substring Between Two Equal Characters
  292. Slowest Key
  293. Sort Array by Increasing Frequency
  294. Check Array Formation Through Concatenation
  295. Get Maximum in Generated Array
  296. Design an Ordered Stream
  297. Check If Two String Arrays are Equivalent
  298. Maximum Repeating Substring
  299. Richest Customer Wealth
  300. Goal Parser Interpretation
  301. Count the Number of Consistent Strings
  302. Count of Matches in Tournament
  303. Reformat Phone Number
  304. Number of Students Unable to Eat Lunch
  305. Determine if String Halves Are Alike
  306. Maximum Units on a Truck
  307. Decode XORed Array
  308. Number Of Rectangles That Can Form The Largest Square
  309. Find the Highest Altitude
  310. Latest Time by Replacing Hidden Digits
  311. Maximum Number of Balls in a Box
  312. Sum of Unique Elements
  313. Check if Array Is Sorted and Rotated
  314. Minimum Changes To Make Alternating Binary String
  315. Merge Strings Alternately
  316. Count Items Matching a Rule
  317. Find Nearest Point That Has the Same X or Y Coordinate
  318. Check if Binary String Has at Most One Segment of Ones
  319. Check if One String Swap Can Make Strings Equal
  320. Find Center of Star Graph
  321. Second Largest Digit in a String
  322. Maximum Ascending Subarray Sum
  323. Number of Different Integers in a String
  324. Truncate Sentence
  325. Sign of the Product of an Array
  326. Minimum Operations to Make the Array Increasing
  327. Check if the Sentence Is Pangram
  328. Sum of Digits in Base K
  329. Replace All Digits with Characters
  330. Minimum Distance to the Target Element
  331. Maximum Population Year
  332. Sorting the Sentence
  333. Sum of All Subset XOR Totals
  334. Longer Contiguous Segments of Ones than Zeros
  335. Check if Word Equals Summation of Two Words
  336. Check if All the Integers in a Range Are Covered
  337. Redistribute Characters to Make All Strings Equal
  338. Largest Odd Number in String
  339. Remove One Element to Make the Array Strictly Increasing