Skip to content

CODINGSAINT/leetcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

language licence twitter

Leetcode Solutions Java

This is a personal journey to leetcode of Kumar Pallav . The solutions are mostly in Java.

String

No Question Level Solution
520 Detect Capital Easy DetectCapital
1221 Split a String in Balanced Strings Easy SplitaStringinBalancedStrings
345 Reverse Vowels of a String Easy ReverseVowelsofaString
344 Reverse String Easy ReverseString
804 Unique Morse Code Words Easy UniqueMorseCodeWords
1436 Destination City Easy DestinationCity
859 Buddy Strings Easy BuddyString
316 Remove Duplicate Letters Easy RemoveDuplicateLetters
819 Most Common Word Easy MostCommonWord
1002 Find Common Characters Easy FindCommonCharacters
1446 Consecutive Characters Easy ConsecutiveCharacters
1614 Maximum Nesting Depth of the Parentheses Easy MaximumNestingDepthoftheParentheses
1370 Increasing Decreasing String Easy MaximumNestingDepthoftheParentheses
1662 Check If Two String Arrays are Equivalent Easy CheckIfTwoStringArraysareEquivalent
809 Expressive Words Medium ExpressiveWords
/1694/Reformat Phone Number ReformatPhoneNumber
1704 Determine if String Halves Are Alike Easy DetermineifStringHalvesAreAlike

Arrays

No Question Level Solution

| 1480 | Running Sum of 1d Array|Easy| RunningSumof1dArray| | 1431 | Kids With the Greatest Number of Candies|Easy |KidsWithTheGreatestNumberofCandies| | 1309 |Decrypt String from Alphabet to Integer Mapping|Easy|DecryptStringfromAlphabettoIntegerMapping| | 1389 |Create Target Array in the Given Order |Easy | CreateTargetArrayintheGivenOrder| | 1450 |Number of Students Doing Homework at a Given Time |Easy | NumberofStudentsDoingHomeworkataGivenTime| | 1313 | Decompress Run-Length Encoded List| Easy | DecompressRunLengthEncodedList| | 220 |Contains Duplicate III|Medium | ContainsDuplicateIII| |1380| Lucky Numbers in a Matrix| Easy |LuckyNumbersinaMatrix| |682| Baseball Game| Easy |Baseball Game| | 1572 | Matrix Diagonal Sum|Easy| MatrixDiagonalSum| |389 |Find the Difference| Easy | FindtheDifference| |977| Squares of a Sorted Array| Easy |SquaresofaSortedArray| | 1295 | Find Numbers with Even Number of Digits|Easy| FindNumberswithEvenNumberofDigits| |1266 |Minimum Time Visiting All Points| Easy | MinimumTimeVisitingAllPoints| |202| Happy Number| Easy | HappyNumber| |1588| Sum of All Odd Length Subarrays| Easy | SumofAllOddLengthSubarrays| |39| CombinationSum | Medium | CombinationSum| |1288| Remove Covered Intervals| Medium | RemoveCoveredIntervals| |1464| Maximum Product of Two Elements in an Array| Easy | MaximumProductofTwoElementsinanArray| |832| Flipping an Image| Easy | FlippinganImage| |1051|Height Checker|Easy|HeightChecker| |1351|Count Negative Numbers in a Sorted Matrix|Easy|CountNegativeNumbersinaSortedMatrix| |189|Rotate Array| Medium | RotateArray| |1486| XOR Operation in an Array| Easy| XOROperationinanArray| |1252|Cells with Odd Values in a Matrix| Easy| CellwithOddValuesinaMatrix| |41|First Missing Positive|Hard | FirstMissingPositive| |74|Search a 2D Matrix|Medium | Searcha2DMatrix| |1299|Replace Elements with Greatest Element on Right Side|Easy | ReplaceElementswithGreatestElementonRightSide| |238| Product of Array Except Self|Medium | ProductofArrayExceptSelf| |1329|Sort the Matrix Diagonally|Medium | SorttheMatrixDiagonally| |532|K-diff Pairs in an Array|Medium | KdiffPairsinanArray| |1460| Make Two Arrays Equal by Reversing Sub-arrays| Easy| MakeTwoArraysEqualbyReversingSubarrays| |228| Summary Ranges| Easy| SummaryRanges| |118| Pascal's Triangle| Easy| PascalsTriangle| |849| Maximize Distance to Closest Person| Medium | MaximizeDistancetoClosestPerson| |419|Battleships in a Board|Medium| BattleshipsinaBoard| |1476|Subrectangle Queries|Medium|SubrectangleQueries| |1640|Check Array Formation Through Concatenation | Easy| CheckArrayFormationThroughConcatenation| |1304| Find N Unique Integers Sum up to Zero|Easy| FindNUniqueIntegersSumuptoZero| |1637| Widest Vertical Area Between Two Points Containing No Points | Medium | WidestVerticalAreaBetweenTwoPointsContainingNoPoints| |845|Longest Mountain in Array| Medium | LongestMountaininArray| |56|Merge Intervals | Medium | MergeIntervals| |48|Rotate Image|Medium| RotateImage| |53| Maximum Subarray|Easy| MaximumSubarray| |1222| Queens That Can Attack the King|Medium | QueensThatCanAttacktheKing| |75| Sort Colors | Medium | SortColors| |283|Move Zeroes | Medium | MoveZeroes| |15|3Sum|Medium| ThreeSum| |217|Contains Duplicate|Easy| ContainsDuplicate| |4|Median of Two Sorted Arrays|Hard| MedianofTwoSortedArrays| |287|Find the Duplicate Number|Medium| FindtheDuplicateNumber| |448|Find the Duplicate Number|Easy| FindAllNumbersDisappearedinanArray| |442|Find All Duplicates in an Array|Medium| FindAllDuplicatesinanArray |169|Majority Element|Easy| MajorityElement| |1710|Maximum Units on a Truck|Easy| MaximumUnitsonaTruck| |1711|Count Good Meals|Medium| CountGoodMeals| |457|Circular Array Loop|Medium| CircularArrayLoop|

Stack

No Question Level Solution
125 Valid Palindrome Easy ValidPalindrome
1021 Remove Outermost Parentheses Easy RemoveOutermostParentheses
1047 Remove All Adjacent Duplicates In String Easy RemoveAllAdjacentDuplicatesInString
496 Next Greater Element I Easy NextGreaterElementI
1544 Make The String Great Easy MakeTheStringGreat
232 Implement Queue using Stacks Easy ImplementQueueusingStacks
844 Backspace String Compare Easy BackspaceStringCompare
155 Min Stack Easy MinStack
20 Valid Parentheses (Easy) ValidParentheses
1190 Reverse Substrings Between Each Pair of Parentheses Easy ReverseSubstringsBetweenEachPairofParentheses
1249 Minimum Remove to Make Valid Parentheses MinimumRemovetoMakeValidParentheses
921 Minimum Add to Make Parentheses Valid Medium MinimumAddtoMakeParenthesesValid
735 Asteroid Collision Medium AsteroidCollison
456 132 Pattern Medium _132Pattern
1381 Design a Stack With Increment Operation Medium DesignaStackWithIncrementOperation
394 Decode String Medium DecodeString
1598 Crawler Log Folder Easy CrawlerLogFolder
227 Basic Calculator II Medium BasicCalculatorII
1541 Minimum Insertions to Balance a Parentheses String Medium MinimumInsertionstoBalanceaParenthesesString

LinkedList

No Question Level Solution
876 Middle of the Linked List Easy MiddleoftheLinkedList
237 Delete Node in a Linked List Easy DeleteNodeinaLinkedList
206 Reverse Linked List Easy ReverseLinkedList
21 Merge Two Sorted Lists Easy MergeTwoSortedLists
83 Remove Duplicates from Sorted List Easy RemoveDuplicatesfromSortedList
141 Linked List Cycle Easy LinkedListCycle
142 Linked List Cycle II Medium LinkedListCycleII
160 Intersection of Two Linked Lists Easy IntersectionofTwoLinkedLists
328 Odd Even Linked List Easy OddEvenLinkedList
725 Split Linked List in Parts Easy SplitLinkedListinParts
1019 Next Greater Node In Linked List Easy NextGreaterNodeInLinkedList
234 Palindrome Linked List PalindromeLinkedList
24 Swap Nodes in Pairs SwapNodesinPairs
109 Convert Sorted List to Binary Search Tree Medium ConvertSortedListtoBinarySearchTree
61 Rotate List Medium RotateList
2 Add Two Numbers Medium AddTwoNumbers
148 Sort List Medium SortList
1290 Convert Binary Number in a Linked List to Integer Easy ConvertBinaryNumberinaLinkedListtoInteger
147 Insertion Sort List Medium InsertionSortList
445 Add Two Numbers II Medium AddTwoNumbersII
382 Linked List Random Node MEDIUM LinkedListRandomNode
1721 Swapping Nodes in a Linked List Medium SwappingNodesinaLinkedList

Hashtable

No Question Level Solution
1512 Valid Palindrome Easy NumberofGoodPairs
771 Jewels and Stones Easy JewelAndStones
739 Daily Temperatures Easy DailyTemperatures
94 Binary Tree Inorder Traversal Easy BinaryTreeInorderTraversal
1 Two Sum Easy TwoSum
1207 Unique Number of Occurrences Easy UniqueNumberofOccurrences
187 Repeated DNA Sequences Medium RepeatedDNASequences

Tree

No Question Level Solution
938 Range Sum of BST Easy RangeSumofBST
617 Merge Two Binary Trees Easy MergeTwoBinaryTrees
700 Search in a Binary Search Tree Easy SearchinaBinarySearchTree
266 Invert Binary Tree Easy InvertBinaryTree
589 N-ary Tree Preorder Traversal Easy NaryTreePreorderTraversal
145 Binary Tree Postorder Traversal Medium BinaryTreePostorderTraversal
897 Increasing Order Search Tree Easy IncreasingOrderSearchTree
590 N-ary Tree Postorder Traversal Easy NaryTreePostorderTraversal
144 Binary Tree Preorder Traversal Medium BinaryTreePreorderTraversal
965 Univalued Binary Tree Easy UnivaluedBinaryTree
102 Binary Tree Level Order Traversal Medium BinaryTreeLevelOrderTraversal
104 Maximum Depth of Binary Tree Easy MaximumDepthofBinaryTree
874 Leaf-Similar Trees Easy LeafSimilarTrees
637 Average of Levels in Binary Tree Easy AverageofLevelsinBinaryTree
669 Trim a Binary Search Tree Easy TrimaBinarySearchTree
538 Convert BST to Greater Tree Easy ConvertBSTtoGreaterTree
635 Two Sum IV - Input is a BST Easy TwoSumIVInputisaBST
606 Construct String from Binary Tree Easy ConstructStringfromBinaryTree
107 Binary Tree Level Order Traversal II Easy BinaryTreeLevelOrderTraversalII
100 Same Tree Easy SameTree
100 Sum of Left Leaves Easy SumofLeftLeaves
993 Cousins in Binary Tree Easy CousinsinBinaryTree
257 Binary Tree Paths Easy BinaryTreePaths
235 Lowest Common Ancestor of a Binary Search Tree Easy LowestCommonAncestorofaBinarySearchTree
563 Binary Tree Tilt Easy BinaryTreeTilt
101 Symmetric Tree Easy SymmetricTree
572 Subtree of Another Tree Easy SubtreeofAnotherTree
1379 Find a Corresponding Node of a Binary Tree in a Clone of That Tree Easy ClonedTarget
513 Find Bottom Left Tree Value Medium FindBottomLeftTreeValue
108 Convert Sorted Array to Binary Search Tree Easy ConvertSortedArraytoBinarySearchTree
1302 Deepest Leaves Sum Medium DeepestLeavesSum
1315 Sum of Nodes with Even-Valued Grandparent Medium SumofNodeswithEvenValuedGrandparent
671 Second Minimum Node In a Binary Tree Easy SecondMaxNodeInaBinaryTree
1161 Maximum Level Sum of a Binary Tree Easy MaximumLevelSumofaBinaryTree
111 Minimum Depth of Binary Tree Easy MinimumDepthofBinaryTree
559 Maximum Depth of N-ary Tree Easy MaximumDepthofNaryTree
112 Path Sum Easy PathSum
802 Find Eventual Safe States Medium FindEventualSafeStates
701 Insert into a Binary Search Tree Medium InsertintoaBinarySearchTree
450 Delete Node in a BST Medium DeleteNodeinaBST
1008 Construct Binary Search Tree from Preorder Traversal Medium ConstructBinarySearchTreefromPreorderTraversal
103 Binary Tree Zigzag Level Order Traversal Medium BinaryTreeZigzagLevelOrderTraversal
199 Binary Tree Right Side View Medium BinaryTreeRightSideView
1609 Even Odd Tree Medium EvenOddTree
1038 Binary Search Tree to Greater Sum Tree Medium BinarySearchTreetoGreaterSumTree
1448 Count Good Nodes in Binary Tree Medium CountGoodNodesinBinaryTree
99 Recover Binary Search Tree Hard RecoverBinarySearchTree
1026 Maximum Difference Between Node and Ancestor Medium MaximumDifferenceBetweenNodeandAncestor
116 Populating Next Right Pointers in Each Node Medium PopulatingNextRightPointersinEachNode
230 Kth Smallest Element in a BST Medium KthSmallestElementinaBST
1261 Find Elements in a Contaminated Binary Tree Medium FindElementsinaContaminatedBinaryTree
1110 Delete Nodes And Return Forest Medium DeleteNodesAndReturnForest
113 Path Sum II Medium PathSumII
814 Binary Tree Pruning Medium BinaryTreePruning
865 Smallest Subtree with all the Deepest Nodes Medium SmallestSubtreewithalltheDeepestNodes

Graph

No Question Level Solution
997 Find the Town Judge Easy FindtheTownJudge
1042 Flower Planting With No Adjacent Easy FlowerPlantingWithNoAdjacent
841 Keys and Rooms Medium KeysandRooms
1306 Jump Game III Medium JumpGameIII
1267 Count Servers that Communicate Medium CountServersthatCommunicate
207 Course Schedule Medium CourseSchedule
684 Redundant Connection Medium RedundantConnection
332 Reconstruct Itinerary Medium ReconstructItinerary
210 Course Schedule II Medium CourseScheduleII
1557 Minimum Number of Vertices to Reach All Nodes Medium MinimumNumberofVerticestoReachAllNodes
1387 Sort Integers by The Power Value Medium SortIntegersbyThePowerValue
785 Is Graph Bipartite? Medium IsGraphBipartite
547 Friend Circles Medium FriendCircles
547 Friend Circles Medium FriendCircles
133 Clone Graph Medium CloneGraph
310 Minimum Height Trees Medium MinimumHeightTrees

Math

No Question Level Solution
949 Largest Time for Given Digits Easy LargestTimeforGivenDigits
7 Reverse Integer Easy ReverseInteger
728 Self Dividing Numbers Easy SelfDividingNumbers
204 Count Primes Easy CountPrimes
799 Champagne Tower Medium ChampagneTower
1217 Minimum Cost to Move Chips to The Same Position Easy MinimumCosttoMoveChipstoTheSamePosition
593 Valid Square Medium ValidSquare
458 Poor Pigs Medium PoorPig

Binary Search

No Question Level Solution
704 Binary Search Easy BinarySearch
153 Find Minimum in Rotated Sorted Array Medium FindMinimuminRotatedSortedArray
33 Search in Rotated Sorted Array Medium SearchinRotatedSortedArray
81 Search in Rotated Sorted Array II Medium SearchinRotatedSortedArrayII

Sorting

No Question Level Solution
452 Minimum Number of Arrows to Burst Balloons Medium MinimumNumberofArrowstoBurstBalloons

Greedy

No Question Level Solution
1007 Minimum Domino Rotations For Equal Row Medium MinimumDominoRotationsForEqualRow
392 Is Subsequence Easy IsSubsequence
948 Bag of Tokens Medium BagofTokens
1094 Car Pooling Medium CarPooling
1685 Sum of Absolute Differences in a Sorted Array Medium SumofAbsoluteDifferencesinaSortedArray

Dynamic Programming

No Question Level Solution
198 House Robber Easy HouseRobber
213 House Robber II Easy HouseRobberII
746 Min Cost Climbing Stairs Easy MinCostClimbingStairs
70 Climbing Stairs Easy ClimbingStairs
121 Best Time to Buy and Sell Stock Easy BestTimetoBuyandSellStock
123 Best Time to Buy and Sell Stock III Hard BestTimetoBuyandSellStockIII
1510 Stone Game IV Hard StoneGameIV
300 Longest Increasing Subsequence Medium LongestIncreasingSubsequence
673 Number of Longest Increasing Subsequence Medium NumberofLongestIncreasingSubsequence
902 Numbers At Most N Given Digit Set Hard NumbersAtMostNGivenDigitSet
902 House Robber III Medium HouseRobberIII
1641 Count Sorted Vowel Strings Medium CountSortedVowelStrings
416 Partition Equal Subset Sum Medium PartitionEqualSubsetSum
62 Unique Paths Medium UniquePaths
63 Unique Paths II Medium UniquePathsII
70 Climbing Stairs Easy ClimbingStairs
1690 Stone Game VII Medium Stone Game VII

Backtracking

No Question Level Solution
1242 Iterator for Combination Medium IteratorforCombination
47 Permutations II Medium PermutationsII

Sliding Windows

No Question Level Solution
395 Longest Substring with At Least K Repeating Character Medium LongestSubstringwithAtLeastKRepeatingCharacter
1052 Grumpy Bookstore Owner Medium GrumpyBookstoreOwner
3 Longest Substring Without Repeating Characters Medium LongestSubstringWithoutRepeatingCharacters
1456 Maximum Number of Vowels in a Substring of Given Length Medium MaximumNumberofVowelsinaSubstringofGivenLength
904 Fruit Into Baskets Medium FruitIntoBaskets
424 Longest Repeating Character Replacement Medium LongestRepeatingCharacterReplacement
76 Minimum Window Substring Hard MinimumWindowSubstring
438 Find All Anagrams in a String Medium FindAllAnagramsinaString

Breadth First Search

No Question Level Solution
1345 Jump Game IV Hard JumpGameIV

Multithreading

No Question Level Solution
1114 Print in Order Easy PrintinOrder
1115 Print FooBar Alternately Medium PrintFooBarAlternately

Misc

No Question Level Solution
1242 Number of Steps to Reduce a Number to Zero Easy NumberofStepstoReduceaNumbertoZero
1365 How Many Numbers Are Smaller Than the Current Number Easy HowManyNumbersAreSmallerThantheCurrentNumber
1281 Subtract the Product and Sum of Digits of an Integer Easy SubtracttheProductandSumofDigitsofanInteger
1009 Complement of Base 10 Integer Easy ComplementofBase10Integer
1603 Design Parking System Easy DesignParkingSystem

#Heap

No Question Level Solution
1705 Maximum Number of Eaten Apples Medium MaximumNumberofEatenApples
73 K Closest Points to Origin Medium KClosestPointstoOrigin
1046 Last Stone Weight Easy LastStoneWeight
703 Kth Largest Element in a Stream Easy KthLargestElementinaStream

Sql

No Question Level Solution
595 Big Countries Easy BigCountries

Bitwise

No Question Level Solution
1720Decode XORed Array Easy DecodeXORedArray)