Skip to content

This repository consists of solutions to the problem from LeetCode platform. Subscribe to our Channel for more updates

License

NotificationsYou must be signed in to change notification settings

mandradem/LeetCode-Solutions

 
 

Repository files navigation

Join Us on Telegram & Facebook

LOCStars BadgeForks BadgeGitHub contributors


Language  License  contributions welcomeDiscordfirst-timers-only-friendly

Got stuck in a LeetCode question?

This repository will help you by providing approach of solving the problems from LeetCode platform.

Contributors helped us in providing these Awesome solutions.

If you want to contribute, please create a Pull Request. If you are new to please check pull request procedure ---> PR process

Check out ---> Sample PR

  • There are new LeetCode questions every week. I'll keep updating for full summary and better solutions.
  • For more challenging problem solutions, you can also see our HackerRank-Solutions, ProjectEuler repositories.
  • Hope you enjoy the journey of learning data structures and algorithms.
  • Notes: "🔒" means your subscription of LeetCode premium membership is required for reading the question.

Don't forget to give us a 🌟 to support us.

Check out -> Learning Resources

Algorithms

Bit Manipulation

#TitleSolutionTimeSpaceDifficultyTagTutorial
136Single NumberJava
Python
C++
JavaScript
O(n)O(1)EasyUsing XOR
137Single Number IIPython
C++
O(n)O(1)Medium
260Single Number IIIPython
C++
O(n)O(1)Medium
371Sum of Two IntegersJavaO(1)O(1)Medium
476Number ComplementJava
C++
O(1)O(1)EasyTutorial
520Detect Capital UsePython
C++
O(n)O(1)Easy
1486XOR Operation in an ArrayJava
C++
O(n)O(1)EasyUsing XOR


Sort

#TitleSolutionTimeSpaceDifficultyTagTutorial
973K Closest Points to OriginC++O(n)O(1)Medium


Array

#TitleSolutionTimeSpaceDifficultyNoteVideo Explaination
118Pascal's TriangleJavaO(N^2)O(N)Easy
56Merge IntervalsPythonO(nlogn)O(n)MediumIntervals
268Missing NumberJavaO(n)O(1)EasyArrayTutorial
697Degree of an ArrayJavaO(n)O(n)EasyArray
1089Duplicate ZeroesJavaScriptO(n)O(n)EasyArray
1502Can Make Arithmetic Progression From SequenceJavaO(n)O(1)EasyArray
122Best Time to buy and sell Stock IIPython
C++
O(N)O(1)MediumStocks
119Pascal's Triangle IIPythonO(N^2)O(K)Easy
1480Running Sum of 1d ArrayJavaO(N)O(N)EasySimple sum
42Trapping Rain WaterPythonO(N^2)O(N)HardArray
11Container with Most WaterPythonO(N)O(N)MediumArray Two Pointers
1134 🔒Armstrong NumberJavaO(N)O(1)Easy
1534Count Good TripletsPythonO(N^3)O(1)Easy
1572Matrix Diagonal SumJavaO(N)O(1)Easy
811Subdomain Visit CountJavascriptO(N*M)O(N*M + N)Easy
53Maximum SubarrayC++O(N)O(1)EasyArray
495Teemo AttackingC++O(n)O(1)MediumArray
153 SumPythonO( nLog(n) )O(1)MediumArray
1200Minimum Absolute DifferencePythonO(n)O(1)EasyArray
532K-diff Pairs in an ArrayC++O(n)O(n)MediumArray
152Maximum Product SubarrayJavascriptO(n)O(n)MediumArray
073Set-Matrix-ZeroesJavaO(MN)O(1)MediumArray
1288Remove-Covered-IntervalsC++O(N*N)O(1)MediumArray
189Rotate-ArrayPythonO(N)O(1)MediumArray
496next-greater-element-iPythonO(N)O(1)MediumArray
1470Shuffle the ArrayJavaO(N)O(1)EasyArray
124Permutation by RecussionJavaO(N)O(N)EasyArray
283Move-ZeroesC++O(N)O(1)EasyArray
27Remove-ElementC++O(N)O(1)EasyArray
36Valid SudokuJavaO(N^2)O(N)MediumArray, 2D Matrix
1512Number of Good PairsJavaO(N^2)O(1)EasyArray
162Find Peak elementjavascripto(Logn)O(1)MediumArray
54Spiral MatrixC++O(M*N)O(M*N)MediumArray
238Product of Array Except SelfC++O(N)O(N)MediumArray


String

#TitleSolutionTimeSpaceDifficultyTagNote
3Longest Substring Without Repeating CharactersPythonO(n)O(n)MediumHash Table
Sliding Window
Open for improvisation, mentioned time and space complexities unconfirmed
8String to Integer (atoi)JavaO(n)O(1)Medium
9Palindrome NumberJavaO(n)O(1)Easy
151Reverse Words in a StringJavaO(1)O(n)Medium
383Ransom NoteJavaO(1)O(n)EasyCharacter Count
387First Unique Character in a StringJavaO(n)O(1)EasyCharacter Count
520Detect Capital UseJavaO(n)O(1)Easy
767Reorganize StringPythonO(n)O(n)Medium
859Buddy StringsJavaO(n)O(1)Easy
1221Split a String in Balanced StringsPythonO(n)O(1)Easy
1374Generate a String With Characters That Have Odd CountsJavaO(n)O(1)Easy
1614Maximum Nesting Depth of the ParenthesesJavaO(n)O(1)Easy


Linked List

#TitleSolutionTimeSpaceDifficultyTagTutorial
002Add Two NumbersJavaO(n)O(n)MediumMath
19Remove Nth Node From End of ListJavaO(n)O(1)MediumTwo pointers
23Merge K sorted listsC++O(nlogn)O(n)Hardsorting and append
109Convert Sorted List to Binary Search TreeJavaO(n)O(n)MediumLinkedList
141Linked List CycleJavaO(n)O(1)EasySlow-Fast Pointers
142Linked List Cycle IIJava
C++
O(n)O(1)MediumSlow-Fast Pointers
146LRU CacheC++
Python
O(1)O(k)MediumHash Map
160Intersection of Two Linked ListsJavaO(n)O(1)EasyTwo PointersTutorial
186Middle of the Linked ListJavaO(n)O(1)EasyTwo pointers
143Reorder ListC++O(n)O(n)MediumIteration and Stack
24Swap Nodes in PairsC++O(n)O(1)MediumTwo pointers


Stack

#TitleSolutionTimeSpaceDifficultyTagNote
020Valid ParenthesesPython C++JavaO(n)O(n)EasyStack
084Largest Rectangle in HistogramC++O(n)O(n)HardStack
150Evaluate Reverse Polish NotationPython
Java
O(n)O(1)MediumStack
1047Remove All Adjacent Duplicates In StringC++O(n)O(n)EasyStack
682Baseball GameC++O(n)O(n)EasyStack
1381Design a Stack With Increment OperationJavaO(n)O(n)MediumStack
1598Crawler Log FolderC++O(n)O(n)EasyStack
94Binary Tree Inorder TraversalPythonO(n)O(n)MediumRecursion, Binary Tree
735Asteroid CollisionC++O(n)O(1)MediumStack
394Decode StringC++O(n)O(1)MediumStack
921Minimum Add to Make Parentheses ValidC++O(n)O(1)MediumStack
32Longest Valid ParenthesesPythonO(n)O(n)HardStack
1249Minimum Remove to Make Valid ParenthesesC++O(n)O(n)MediumStack


Queue

#TitleSolutionTimeSpaceDifficultyTagNote
933Number of Recent CallsC++O(1)O(1)EasyQueue, Sliding Window
641Design Circular DequeJavaO(n)O(n)MediumQueue, Design
621Task SchedulerPythonO(n)O(n)MediumQueue
622Design Circular QueuePythonO(n)O(n)MediumQueue


Tree

#TitleSolutionTimeSpaceDifficultyTagNote
094Binary Tree Inorder TraversalJava
Python
O(n)O(logn)MediumBinary Tree, Stack, HashTable
100Same TreePython
Java
O(n)O(n)EasyTree, Depth-first Search
101Symmetric TreeJava
Python
O(n)O(n)EasyTree, Breadth-first Search, Depth-first Search
144Binary Tree Preorder TraversalJava
C++
O(n)O(logn)MediumBinary Tree, Stack
145Binary Tree Postorder TraversalJavaO(n)O(logn)HardBinary Tree, Stack
103ZigZag Level OrderJavaScript
C++
O(n)O(n)MediumBinary Tree
129Sum Root to Leaf NumbersJavaO(n)O(logn)MediumBinary Tree, Depth First Search
307Range Sum Query - MutableJavaO(logn)O(n)MediumSegment Tree
919Complete Binary Tree InserterJavaO(n)O(n)MediumTree
124Binary Tree Maximum Path SumC++O(n)O(n)HardTree
1028Recover a Tree From Preorder TraversalC++O(n)O(n)HardTree
968Binary Tree CamerasC++O(n)O(logn)HardBinary Tree, Dynamic Programming
98Validate Binary Search TreeJavascriptO(log(n))O(log(n))MediumBinary Tree
684Redundant ConnectionJavaO(N)O(N)MediumTree, Union Find
102Binary Tree Level Order TraversalC++O(n)O(n)MediumBinary Tree, map


Hash Table

#TitleSolutionTimeSpaceDifficultyTagVideo Explanation
001Two SumJava
Python
C++
O(N)O(N)EasyTutorial
242Valid AnagramJavaO(n)O(1)EasyTutorial
146LRU CacheJavaMedium
217Contains DuplicatePythonO(n)O(n)
554Brick WallC++O(n)O(n)Medium
049Group AnagramsPythonO(nlogn)O(1)Easy
554Brick WallC++O(n)O(n)Medium
146LRU CacheJavascriptO(log(n))O(n)Medium
389Find The DifferenceC++O(n)O(1)Easy


Two Pointers

#TitleSolutionTimeSpaceDifficultyTagNote
005Longest Palindromic SubstringPython
JavaScript
O(N^2)
O(N^2)
O(N)
O(1)
MediumExpand the Wings
4Median of Two Sorted ArraysJavaO(log(min(m,n)))O(1)Hard
845Longest Mountain in ArrayC++O(N)O(1)MediumTwo Pointer
0153 SumC++O(N)O(1)MediumTwo Pointer
021Merge Two Sorted ListsC++O(N)O(1)EasyTwo Pointer


Math

#TitleSolutionTimeSpaceDifficultyTagNote
050Pow(x, n)Python
JavaScript
O(n)O(1)MediumMath
204Count PrimesC++O(n(log(logn)))O(n)EasyMath
171Excel Sheet Column NumberC++O(n)O(1)EasyString
168Excel Sheet Column TitleC++O(n)O(n)EasyString
007Reverse IntegerJava
C++
O(n)O(n)EasyMath
202Happy NumberJavaO(n^2)O(n)EasyMath
326Power of ThreeJavaO(logn)O(n)EasyMath
12Integer to RomanJavaO(n)O(1)MediumMath
13Roman to IntegerJava
C++
O(n)O(1)EasyMath
14Arithmetic SubarraysJavaO(m*n)O(n)MediumMathPattern Count
263Ugly NumberJavaO(n)O(n)EasyMath
412Fizz BuzzJavaO(n)O(n)EasyMath
1518Water BottlesJavaO(n)O(n)EasyMath
1822Sign Of ProductJavaO(n)O(n)EasyMath
991Broken CalculatorJavaO(n)O(n)MediumMath
1837Sum of Digits in Base KPythonO(n)O(1)EasyMath


Breadth-First Search

#TitleSolutionTimeSpaceDifficultyTagNote
1284Minimum Number of Flips to Convert Binary Matrix to Zero MatrixC++O(m * n * 2 ^ (m * n))O(2 ^ (m * n))HardBFS
200Number of IslandsJavaO(R * C)O(R * C)MediumBFS
127Word LadderJavaO(N^2 * M)O(N * M)MediumBFS
994Rotten OrangesPythonO(N * M)O(N * M)MediumBFS
743Network Delay TimeC++O(V+E))O(V)MediumBFS
111Min Depth of Binary TreeJavaScriptO(nlogn)O(nlogn)EasyBFS
100Same TreeC++O(N)O(N)EasyBFS


Depth-First Search

#TitleSolutionTimeSpaceDifficultyTagNote
1463Cherry Pickup IIC++O(n * m)O(n * m)HardDFS
104Maximum Depth of Binary TreepythonO(n)O(n)EasyDFS
112Path SumJavaO(n)O(n)EasyDFS
110Balanced Binary TreeJavaO(n)O(n)EasyDFS
1376Time Needed to Inform All EmployeesC++O(n)O(n)MediumDFS
200Number of IslandsC++O(m * n)O(m * n)MediumDFS


BackTracking

#TitleSolutionTimeSpaceDifficultyTagNote
037Sudoku SolverC++O(n^2)O(1)HardHash Table
980Unique Paths IIIC++O(R * C * 2 ^ (R * C))O(R * C)HardDFS, Memoization
39Combination SumC++O(2^n)O(n)MediumArray, Backtracking
17Letter Combinations of a Phone NumberC++O(4^n)O(n)MediumString, Hash Table, Backtracking


Dynamic Programming

#TitleSolutionTimeSpaceDifficultyTagNote
416Partition Equal Subset SumC++O(n^2)O(n^2)MediumDP
056Wildcard MatchingPythonO(n^2)O(n^2)Hard
343Integer BreakC++O(n^2)O(n)Medium
139Word BreakPythonO(n^3)O(n)MediumDP
1092Shortest Common SupersequenceC++O(n^2)O(n^2)HardDP
72Edit DistancePythonO(N*M)O(n^2)MediumLevenshtein Distance
91Decode waysPythonO(N)O(N)EasyDP
1025Divisor GamePythonO(N^2)O(N)EasyDP
174Dungeon GameC++O(M*N)O(M*N)HardDynamic Programming
070Climbing StairsJavaO(N)O(1)EasyDP
730Count Different Palindromic SubsequencesC++O(N*N)O(N*N)HardDP
55Jump GamePythonO(N)O(N)MediumDP


Binary Search

#TitleSolutionTimeSpaceDifficultyTagNote
035Search Insert PositionPythonO(logn)O(1)EasyBinary Search
278First Bad VersionJava
JavaScript
O(logn)O(1)EasyBinary Search
033Search in Rotated Sorted ArrayPythonO(logn)O(1)MediumBinary Search
153Find Minimum in Rotated Sorted ArrayPythonO(logn)O(1)MediumBinary Search
704Binary SearchC++O(logn)O(1)EasyBinary Search


Graph

#TitleSolutionTimeSpaceDifficultyTagNote
207Course ScheduleC++O(V+E)O(V+E)MediumGraphCycle Detection in Directed Graph
1042Flower Planting with No AdjacentPythonO(V+E)O(2V+E)MediumGraphGraph Coloring
797All Paths From Source to TargetJavaO(N^2)O(N)MediumGraphDFS
934Shortest BridgeC++O(V)O(V)MediumGraphDFS + BFS
1192Critical Connections in a NetworkC++O(V+E)O(4V+E)HardGraphTarjan's Algorithm
113Path Sum IIC++O(V+E)O(V)MediumGraphDFS
785Is Graph Bipartite?C++O(V+E)O(V)MediumGraphBFS
947Most Stones Removed with Same Row or ColumnC++O(V)O(2V)MediumGraphUnion Find
210Course Schedule IIC++O(V+E)O(V)MediumGraphBFS
1627Graph Connectivity with ThresholdJavaO(V.logV + Q)O(V)HardGraphUnion Find + Sieve
1631Path with Minimum EffortJavaO(V^2)O(V)MediumGraphDijkstra's Shortest Path


Learning Resources

codedecks

1.) ing the Coding Interview (Indian Edition)

2.) Data Structures and Algorithms Made Easy in Java

3.) Data Structure and Algorithmic Thinking with Python

4.) Head First Design Patterns

5.) Dynamic Programming for Coding Interviews

DISCLAIMER: This above mentioned resources have affiliate links, which means if you buy one of the product from my links, I’ll receive a small commission. This helps support the channel and allows us to continue to add more tutorial. Thank you for the support!



Authors


Contributors

NameCountryProgramming LanguageWhere to find you
(add all links to your profiles eg on Hackerrank, Codechef, LeetCode...)
Gourav R
IndiaJavacodedecks
Hackerrank
LeetCode
Dima Vishnevetsky
IsraelJavaScriptTwitter
Facebook
Anuj Sharma
IndiaPython
Lokendra Bohra
IndiaPythonLeetcode
Hackerrank
Yuri Spiridonov
RussiaPythonTwitter
Leetcode
Hackerrank
Naveen Kashyap
IndiaJavascriptTwitter
Leetcode
Rudra Mishra
IndiaC++Twitter
Leetcode
Sachin Singh Negi
IndiaPythonTwitter
Leetcode
Hackerrrak
Girish Thatte
IndiaJavaLeetcode
Hackerrank
Codechef
Kevin Chittilapilly
IndiaJavaLeetcode
Hackerrank
Kaggle
Nour Grati
TunisiaPythonLeetcode
Hackerrank
Twitter
Avinash Trivedi
IndiaC++Leetcode
Ishika Goel
IndiaC++Leetcode
Fenil Dobariya
IndiaJava
Prashansa Tanwar
IndiaC++Leetcode
Ishu Raj
IndiaC++Leetcode
Rakesh Bhadhavath
IndiaJavaLeetcode
Tarun Singh
IndiaC++Leetcode
Hardik Gupta
IndiaC++codeforces
codechef
Hackerrank
LeetCode
Jaseem ck
IndiaPython
Ilias Khan
IndiaC++codechef
Hackerrank
LeetCode
codeforces
Shamoyeeta Saha
IndiaC++Hackerrank
James Y
New Zealandpython
Hamza B
Saudi ArabiaJava
Meli Haktas
Turkeypython
Saurav Prateek
IndiaJava
Codechef
Codeforces
Leetcode
Anushka Verma
IndiaC++Portfolio
LeetCode
James H
United KingdomC++
Franchis N. Saikia
IndiaC++
Yarncha
South KoreaC++LeetCode
Gamez0
South KoreaPythonLeetCode
JeongDaHyeon
South KoreaJava
Aysia
USAJavaScript
Poorvi Garg
IndiaC++
Lakshmanan Meiyappan
IndiaC++Website - Blog

LinekdIn
Sachin_Upadhyay
IndiaJava
Amisha Sahu
IndiaC++CodeChef
LeetCode
HackerRank
Shrimadh V Rao
IndiaC++
Shreyas Shrawage
IndiaPythonCodeChef
LeetCode
HackerRank
Surbhi Mayank
IndiaC++

About

This repository consists of solutions to the problem from LeetCode platform. Subscribe to our Channel for more updates

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 37.7%
  • Java 37.1%
  • Python 19.3%
  • JavaScript 5.9%