Skip to content
On this page
Leetcode

🏆 Curated solutions to Leetcode problems in multiple languages to ace the Coding Interviews.

🔍 Press Ctrl+F or +F to search for a specific problem

#SolutionTagDifficultyRemark
0001Two SumArray, Hash Table
0002Add Two NumbersLinked List, Math, Recursion
0004Median of Two Sorted ArraysArray, Binary Search, Divide & Conquer
0007Reverse IntegerMath
0009Palindrome NumberMath
0013Roman to IntegerString, Math, Hash Table
0014Longest Common PrefixString
0020Valid ParenthesesString, ST
0021Merge Two Sorted ListsLinked List, Recursion
0022Generate ParenthesesString, Dynamic Programming, Backtracking
0024Swap Nodes in PairsLinked List, Recursion
0026Remove DuplicatesArray, Two Pointers
0027Remove ElementArray, Two Pointers
0028Find the Index of the First Occurrence in a StringTwo Pointers, String, String Matching
0035Search Insert PositionArray, BS
0037Sudoku SolverArray, Backtracking, Matrix
0041First Missing PositiveArray, Hash Table
0042Trapping Rain WaterArray, Two Pointers, Dynamic Programming, Stack, Monotonic Stack
0048Rotate ImageArray, Math, Matrix
0051N-QueensArray, Backtracking
0053Maximum SubarrayArray, Divide and Conquer, DP
0055Jump GameArray, Dynamic Programming, Greedy
0058Length of Last WordString
0061Rotate ListLinked List, Two Pointers
0066Plus OneArray, Math
0067Add BinaryMath, String, Bit Manipulation, Simulation
0069Sqrt(x)Math, BS
0070Climbing StairsMath, Dynamic Programming, Memorization
0072Edit DistanceString, DP
0074Search a 2D MatrixArray, Binary Search, Matrix
0075Sort ColorsArray, Two Pointers, Sorting
0078SubsetsArray, Backtracking, Bit Manip
0083Remove Duplicates from Sorted ListLL
0088Merge Sorted ArrayArray, Two Pointers, Sorting
0094Binary Tree Inorder TraversalTree, Stack, Depth First Search, Binary Tree
0098Validate BSTTree, Depth First Search, Binary Search Tree, Binary Tree
0100Same TreeTree, Depth First Search, Breadth First Search, Binary Tree
0101Symmetric TreeTree, Depth-First Search, Breadth-First Search, Binary Tree
0103Binary Tree Zigzag Level Order TraversalTree, Breadth First Search, Binary Tree
0104Maximum Depth of Binary TreeTree, Breadth First Search, Depth First Search, Binary Tree
0106Construct Binary Tree from Inorder and Postorder TraversalArray, Hash Table, Divide and Conquer, Tree, Binary Tree
0108Convert Sorted Array to Binary Search TreeArray, Divide and Conquer, Tree, Binary Search Tree, Binary Tree
0109Convert Sorted List to Binary Search TreeLinked List, Divide and Conquer, Tree, Binary Search Tree, Binary Tree
0110Balanced Binary TreeTree, Depth First Search, Binary Tree
0111Minimum Depth of Binary TreeTree, Depth First Search, Breadth First Search, Binary Tree
0112Path SumTree, Depth-First Search, Breadth-First Search, Binary Tree
0118Pascal's TriangleArray, DP
0119Pascal's Triangle IIArray, DP
0121Best Time to Buy and Sell StockArray, DP
0122Best Time to Buy and Sell Stock IIArray, Dynamic Programming, Greedy
0125Valid PalindromeTwo Pointers, String
0129Sum Root to Leaf NumbersTree, Depth-First Search, Binary Tree
0136Single NumberArray, Bit Manip
0141Linked List CycleHash Table, Linked List, 2P
0142Linked List Cycle IIHash Table, Linked List, 2P
0144Binary Tree Preorder TraversalStack, Tree, Depth First Search, Binary Tree
0145Binary Tree Postorder TraversalStack, Tree, Depth First Search, Binary Tree
0160Intersection of Two Linked ListsHash Table, Linked List, 2P
0169Majority ElementArray, Hash Table, Divide and Conquer, Sorting, Counting
0172Factorial Trailing ZeroesMath
0190Reverse BitsDivide and Conquer, Bit Manip
0191Number of 1 BitsDivide & Conquer, Bit Manipulation
0193Valid Phone NumbersShell
0195Tenth LineShell
0199Binary Tree Right Side ViewTree, Depth First Search, Breadth First Search, Binary Tree
0200Number of IslandsArray, Depth-First Search, Breadth-First Search, Union Find, Matrix
0202Happy NumberHash Table, Math, 2P
0203Remove Linked List ElementsLinked List, Recursion
0205Isomorphic StringsHash Table, String
0206Reverse Linked ListLinked List, Recursion
0211Design Add and Search Words Data StructureString, Depth-First Search, Design, Trie
0217Contains DuplicateArray, Hash Table, Sorting
0219Contains Duplicate IIArray, Hash Table, Sliding Window
0222Count Complete Tree NodesBinary Search, Tree, Depth First Search, Binary Tree
0225Implement Stack using QueuesStack, Design, Q
0226Invert Binary TreeTree, Depth-First Search, Breadth-First Search, Binary Tree
0228Summary RangesArray
0230Kth Smallest Element in a BSTTree, Depth First Search, Binary Search Tree, Binary Tree
0231Power of TwoMath, Bit Manipulation, Recursion
0232Implement Queue using StacksStack, Design, Q
0234Palindrome Linked ListLinked List, Two Pointers, Stack, Recursion
0236Lowest Common Ancestor of a Binary TreeTree, Depth-First Search, Binary Tree
0242Valid AnagramHash Table, String, Sorting
0257Binary Tree PathsString, Backtracking, Tree, Depth-First Search, Binary Tree
0258Add DigitsMath, Simulation, Number Theory
0263Ugly NumberMath
0268Missing NumberArray, Hash Table, Math, Binary Search, Bit Manipulation, Sorting
0278First Bad VersionBinary Search, Interactive
0279Perfect SquaresMath, Dynamic Programming, Breadth-First Search
0283Move ZeroesArray, Two Pointers
0290Word PatternHash Table, String
0292Nim GameMath, Brainteaser, Game Theory
0300Longest Increasing SubsequenceArray, Binary Search, DP
0322Coin ChangeArray, Dynamic Programming, BFS
0326Power of ThreeMath, Recursion
0337House Robber IIIDynamic Programming, Tree, Depth First Search, Binary Tree
0338Counting BitsDynamic Programming, Bit Manip
0342Power of FourMath, Bit Manipulation, Recursion
0344Reverse StringTwo Pointers, String, Recursion
0345Reverse Vowels of a StringTwo Pointers, String
0349Intersection of Two ArraysArray, Hash Table, Two Pointers, Binary Search, Sorting
0350Intersection of Two Arrays IIArray, Hash Table, Two Pointers, Binary Search, Sorting
0367Valid Perfect SquareMath, Binary Search
0369Plus One Linked ListLinked List, Math🔒
0374Guess Number Higher or LowerBinary Search, Interactive
0382Linked List Random NodeLinked List, Math, Reservoir Sampling, Randomized
0383Ransom NoteHash Table, String, Counting
0387First Unique Character in a StringHash Table, String, Queue, Counting
0389Find the DifferenceHash Table, String, Bit Manipulation, Sorting
0392Is SubsequenceTwo Pointers, String, DP
0401Binary WatchBacktracking, Bit Manip
0404Sum of Left LeavesTree, Depth-First Search, Breadth-First Search, Binary Tree
0412Fizz BuzzMath, String, Simulation
0414Third Maximum NumberArray, Sorting
0434Number of Segments in a StringString
0438Find All Anagrams in a StringHash Table, String, Sliding Window
0441Arranging CoinsMath, BS
0442Find All DuplicatesArray, Hash Table
0443String CompressionTwo Pointers, String
0445Add Two Numbers IILinked List, Math, Stack
0448Find All Numbers Disappeared in an ArrayArray, Hash Table
0461Hamming DistanceBit Manip
0463Island PerimeterArray, Depth-First Search, Breadth-First Search, Matrix
0476Number ComplementBit Manip
0482License Key FormattingString
0485Max Consecutive OnesArray
0492Construct the RectangleMath
0498Diagonal TraverseArray, Matrix, Simulation
0502IPOArray, Greedy, Sorting, Heap (Priority Queue)
0504Base 7Math
0506Relative RanksArray, Sorting, Heap
0507Perfect NumberMath
0509Fibonacci NumberMath, Recursion, Dynamic Programming, Memoization
0516Longest Palindromic SubsequenceString, DP
0518Coin Change 2Array, DP
0530Minimum Absolute Difference in BSTTree, Depth-First Search, Breadth-First Search, Binary Search Tree, Binary Tree
0540Single Element in a Sorted ArrayArray, BS
0541Reverse String IITwo Pointers, String
0543Diameter of Binary TreeTree, Depth First Search, Binary Tree
0605Can Place FlowersArray, Greedy
0652Find Duplicate SubtreesHash Table, Tree, Depth-First Search, Binary Tree
0653Two Sum IV - Input is a BSTTree, Depth First Search, Binary Search Tree, Binary Tree
0695Max Area of IslandArray, Depth-First Search, Breadth-First Search, Union Find, Matrix
0704Binary SearchArray, Binary Search
0739Daily TemperaturesArray, Stack, Monotonic Stack
0771Jewels and StonesString, Hashtable
0799Minimum Distance Between BST NodesTree, Depth-First Search, Breadth-First Search, Binary Search Tree, Binary Tree
0875Koko Eating BananasArray, BS
0876Middle of the Linked ListLinked List, Two Pointers
0888Fair Candy SwapArray, Hash Table, Binary Search, Sorting
0912Sort an ArrayArray, Divide and Conquer, Sorting, Heap (Priority Queue), Merge Sort, Bucket Sort, Radix Sort, Counting Sort
0944Delete Columns to Make SortedArray, String
0958Check Completeness of a Binary TreeTree, Breadth-First Search, Binary Tree
0997Find the Town JudgeArray, Hash Table, Graph
1011Capacity To Ship Packages Within D DaysArray, BS
1029Two City SchedulingArray, Greedy, Sorting
1047Remove All Adjacent Duplicates In StringString, Stack
1092Shortest Common SupersequenceString, DP
1108Defanging an IP AddressString
1143Longest Common SubsequenceString, DP
1232Check If It Is a Straight LineArray, Math, Geometry
1345Jump Game IVArray, Hash Table, Breadth-First Search
1431Kids With the Greatest Number of CandiesArray
1461Check If a String Contains All Binary Codes of Size KString, Hash Table, Bit Manipulation
1472Design Browser HistoryArray, Linked List, Stack, Design, Doubly-Linked List, Data Stream
1480Running Sum of 1d ArrayArray, Prefix Sum
1491Average Salary Excluding the Minimum and MaximumArray, Sorting
1498Number of Subsequences That Satisfy the Given Sum ConditionArray, Two Pointer, Binary Search, Sorting
1512Number of Good PairsArray, Hash Table, Math, Counting
1537Get the Maximum ScoreArray, Two Pointer, Dynamic Programming, Greedy
1539Kth Missing Positive NumberArray, BS
1580Shuffle the ArrayArray
1630Count Odd Numbers in an Interval RangeMath
1672Richest Customer WealthArray, Matrix
1689Partitioning Into Minimum Number Of Deci-Binary NumbersString, Greedy
1920Build Array from PermutationArray, Simulation
1929Concatenation of ArrayArray
1957Delete Characters to Make Fancy StringString
2011Final Value of Variable After Performing OperationsArray, String, Simulation
2114Maximum Number of Words Found in SentencesArray, String
2160Minimum Sum of Four Digit Number After Splitting DigitsMath, Greedy, Sorting
2176Count Equal and Divisible Pairs in an ArrayArray
2187Minimum Time to Complete TripsArray, BS
2235Add Two IntegersMath
2236Root Equal to Sum of ChildrenTree, Binary Tree
2348Number of Zero-Filled SubarraysArray, Math
2396Strictly Palindromic NumberMath, Two Pointers, Brainteaser
2413Smallest Even MultipleMath, Number Theory
2427Number of Common FactorsMath, Enumeration, Number Theory
2444Count Subarrays With Fixed BoundsArray, Queue, Sliding Window, Monotonic Queue
2469Convert the TemperatureMath
2551Put Marbles in BagsArray, Greedy, Sorting, Heap (Priority Queue)
2574Left and Right Sum DifferencesArray, Prefix Sum

Released under the MIT License.