This is a repository to document all of my answers to leetcode problems.
Most questions are not optimized, they simply are just accepted answers with not-so-interesting running time and space complexity.
My Leetcode Profile can be found in this link
I have also participated in some of the contests starting from May 13, 2023.
The answers to my contests will be listed in the respective directories, but will not be updated in this README.md
file.
If I was able to solve the problem during the contest, I will also document it under the respective Easy
, Medium
, Hard
directory.
- #1 twoSum.py
- #9 isPalindrome.py
- #13 romanToInt.py
- #20 isValid.py
- #21 mergeTwoLists.py
- #53 maxSubArray.py
- #70 climbStairs.py
- #83 deleteDuplicates.py
- #88 merge.py
- #94 inorderTraversal.py
- #100 isSameTree.py
- #101 isSymmetric.py
- #104 maxDepth.py
- #108 sortedArrayToBST.py
- #111 minDepth.py
- #112 hasPathSum.py
- #116 connect.py
- #118 generate.py
- #119 getRow.py
- #121 maxProfit.py
- #136 singleNumber.py
- #141 hasCycle.py
- #144 preorderTraversal.py
- #145 postorderTraversal.py
- #160 getIntersectionNode.py
- #167 twoSum.py
- #168 convertToTitle.py
- #169 majorityElement.py
- #175 combineTwoTables
- #182 duplicateEmails
- #183 customersWhoNeverOrder
- #190 reverseBits.py
- #191 hammingWeight.py
- #196 deleteDuplicateEmails
- #197 risingTemperature
- #202 isHappy.py
- #203 removeElements.py
- #206 reverseList.py
- #217 containsDuplicate.py
- #225 MyStack.py
- #226 invertTree.py
- #228 summaryRanges.py
- #231 isPowerOfTwo.py
- #232 MyQueue.py
- #234 isPalindrome.py
- #235 lowestCommonAncestor.py
- #242 isAnagram.py
- #278 firstBadVersion.py
- #283 moveZeroes.py
- #290 wordPattern.py
- #303 NumArray.py
- #344 reverseString.py
- #345 reverseVowels.py
- #350 intersect.py
- #374 guessNumber.py
- #383 canConstruct.py
- #387 firstUniqChar.py
- #389 findTheDifference.py
- #392 isSubsequence.py
- #404 sumOfLeftLeaves.py
- #409 longestPalindrome.py
- #412 fizzBuzz.py
- #415 addStrings.py
- #434 countSegments.py
- #459 repeatedSubstringPattern.py
- #476 findComplement.py
- #496 nextGreaterElement.py
- #501 findMode.py
- #511 gamePlayAnalysisI
- #520 detectCapitalUse.py
- #530 getMinimumDifference.py
- #557 reverseWords.py
- #566 matrixReshape.py
- #584 findCustomerReferee
- #586 customersPlacingTheLargestNumberOfOrders
- #589 preorder.py
- #595 bigCountries
- #607 salesPerson
- #617 mergeTrees.py
- #627 swapSalary
- #653 findTarget.py
- #693 hasAlternatingBits.py
- #700 searchBST.py
- #703 KthLargest.py
- #704 search.py
- #705 MyHashSet.py
- #706 myHashMap.py
- #709 toLowerCase.py
- #733 floodFill.py
- #744 nextGreatestLetter.py
- #746 minCostClimbingStairs.py
- #747 dominantIndex.py
- #762 countPrimeSetBits.py
- #783 minDiffInBST.py
- #796 rotateString.py
- #859 buddyStrings.py
- #860 lemonadeChange.py
- #876 middleNode.py
- #883 projectionArea.py
- #905 sortArrayByParity.py
- #922 sortArrayByParityII.py
- #944 minDeletionSize.py
- #953 isAlienSorted.py
- #976 largestPerimeter.py
- #977 sortedSquares.py
- #989 addToArrayForm.py
- #997 findJudge.py
- #1050 actorsAndDirectorsWhoCooperatedAtLeastThreeTimes
- #1071 gcdOfStrings.py
- #1084 salesAnalysisIII
- #1122 relativeSortArray.py
- #1137 tribonacci.py
- #1141 userActivityForThePast30DaysI
- #1148 articleViewsI
- #1232 checkStraightLine.py
- #1281 subtractProductAndSum.py
- #1287 findSpecialInteger.py
- #1290 getDecimalValue.py
- #1309 freqAlphabets.py
- #1331 arrayRankTransform.py
- #1337 kWeakestRows.py
- #1342 numberOfSteps.py
- #1346 checkIfExist.py
- #1351 countNegatives.py
- #1356 sortByBits.py
- #1365 smallerNumberThanCurrent.py
- #1407 topTravellers
- #1413 minStartValue.py
- #1437 kLengthApart.py
- #1455 isPrefixOfWord.py
- #1470 shuffle.py
- #1475 finalPrices.py
- #1484 groupSoldProductsByTheDate
- #1491 average.py
- #1502 canMakeArithmeticProgression.py
- #1523 countOdds.py
- #1527 patientsWithACondition
- #1566 containsPattern.py
- #1572 diagonalSum.py
- #1581 customerWhoVisitedButDidNotMakeAnyTransactions
- #1587 bankAccountSummaryII
- #1588 sumOddLengthSubarrays.py
- #1603 ParkingSystem.py
- #1608 specialArray.py
- #1629 slowestKey.py
- #1652 decrypt.py
- #1667 fixNamesInATable
- #1672 maximumWealth.py
- #1678 interpret.py
- #1693 dailyLeadsAndPartners
- #1729 findFollowersCount
- #1732 largestAltitude.py
- #1736 maximumTime.py
- #1741 findTotalTimeSpentByEachEmployee
- #1757 recyclableAndLowFats
- #1768 mergeAlternately.py
- #1779 nearestValidPoint.py
- #1790 areAlmostEqual.py
- #1791 findCenter.py
- #1795 rearrangeProductsTable
- #1822 arraySign.py
- #1854 maximumPopulation.py
- #1873 calculateSpecialBonus
- #1876 countGoodSubstrings.py
- #1890 theLatestLoginIn2020
- #1957 makeFancyString.py
- #1965 employeesWithMissingInformation
- #1967 numOfStrings.py
- #1971 validPath.py
- #2037 minMovesToSeat.py
- #2053 kthDistinct.py
- #2085 countWords.py
- #2089 targetIndices.py
- #2455 averageValue.py
- #2490 isCircularSentence.py
- #2553 separateDigits.py
- #2558 pickGifts.py
- #2626 reduce.js
- #2629 compose.js
- #2639 findColumnWidth.py
- #2656 maximizeSum.py
- #2670 distinctDifferenceArray.py
- #2678 countSeniors.py
- #2716 minimizedStringLength.py
- #2717 semiOrderedPermutation.py
- #2739 distanceTraveled.py
- #3264 getFinalState.py
- #3354 countValidSelections.py
- #6395 buyChoco.py
- #6430 circularGameLosers.py
- #6439 minLength.py
- #6440 differenceOfDistinctValues.py
- #6454 makeSmallestPalindrome.py
- #6457 removeTrailingZeros.py
- #6461 isFascinating.py
- #6465 smallestString.py
- #6470 findNonMinOrMax.py
- #6892 maximumNumberOfStringPairs.py
- #2 addTwoNumbers.py
- #3 lengthOfLongestSubstring.py
- #5 longestPalindrome.py
- #6 convert.py
- #8 myAtoi.py
- #11 maxArea.py
- #15 threeSum.py
- #17 letterCombinations.py
- #18 fourSum.py
- #19 removeNthFromEnd.py
- #24 swapPairs.py
- #33 search.py
- #34 searchRange.py
- #36 isValidSudoku.py
- #43 multiply.py
- #46 permute.py
- #48 rotate.py
- #49 groupAnagrams.py
- #53 maxSubArray.py
- #56 merge.py
- #59 generateMatrix.py
- #61 rotateRight.py
- #74 searchMatrix.py
- #75 sortColors.py
- #77 combine.py
- #81 search.py
- #82 deleteDuplicates.py
- #86 partition.py
- #91 numDecodings.py
- #93 restoreIpAddresses.py
- #95 generateTrees.py
- #98 isValidBST.py
- #102 levelOrder.py
- #103 zigzagLevelOrder.py
- #105 buildTree.py
- #113 pathSum.py
- #129 sumNumbers.py
- #133 cloneGraph.py
- #138 copyRandomList.py
- #139 wordBreak.py
- #142 detectCycle.py
- #143 reorderList.py
- #146 LRUCache.py
- #148 sortList.py
- #155 MinStack.py
- #162 findPeakElement.py
- #173 BSTIterator.py
- #176 secondHighestSalary
- #187 findRepeatedDnaSequences.py
- #189 rotate.py
- #199 rightSideView.py
- #215 findKthLargest.py
- #223 computeArea.py
- #230 kthSmallest.py
- #236 lowestCommonAncestor.py
- #238 productExceptSelf.py
- #240 searchMatrix.py
- #287 findDuplicate.py
- #300 lengthOfLIS.py
- #319 bulbSwitch.py
- #328 oddEvenList.py
- #334 increasingTriplet.py
- #347 topKFrequent.py
- #373 kSmallestPairs.py
- #386 lexicalOrder.py
- #427 construct.py
- #429 levelOrder.py
- #435 eraseOverlapIntervals.py
- #438 findAnagrams.py
- #447 numberOfBoomerangs.py
- #450 deleteNode.py
- #451 frequencySort.py
- #486 PredictTheWinner.py
- #494 findTargetSumWays.py
- #515 largestValues.py
- #518 change.py
- #524 findLongestWord.py
- #542 updateMatrix.py
- #547 findCircleNum.py
- #560 subarraySum.py
- #567 checkInclusion.py
- #576 findPaths.py
- #608 treeNode
- #646 findLongestChain.py
- #658 findClosestElements.py
- #670 maximumSwap.py
- #695 maxAreaOfIsland.py
- #701 insertIntoBST.py
- #707 MyLinkedList.py
- #713 numSubarrayProductLessThanK.py
- #714 maxProfit.py
- #725 splitListToParts.py
- #763 partitionLabels.py
- #767 reorganizeString.py
- #769 maxChunksToSorted.py
- #779 kthGrammar.py
- #784 letterCasePermutation.py
- #785 isBipartite.py
- #799 champagneTower.py
- #808 soupServings.py
- #837 new21Game.py
- #841 canVisitAllRooms.py
- #863 distanceK.py
- #874 robotSim.py
- #934 shortestBridge.py
- #947 removeStones.py
- #951 flipEquiv.py
- #973 kClosest.py
- #974 subarraysDivByK.py
- #1014 maxScoreSightseeingPair.py
- #1061 smallestEquivalentString.py
- #1072 maxEqualRowsAfterFlips.py
- #1091 shortestPathBinaryMatrix.py
- #1140 stoneGameII.py
- #1146 SnapshotArray.py
- #1158 marketAnalysisI
- #1190 reverseParentheses.py
- #1233 removeSubfolders.py
- #1249 minRemoveToMakeValid.py
- #1318 minFlips.py
- #1347 minSteps.py
- #1367 isSubPath.py
- #1376 numOfMinutes.py
- #1393 capitalGainLoss
- #1396 UndergroundSystem.py
- #1405 longestDiverseString.py
- #1443 minTime.py
- #1457 pseudoPalindromicPaths.py
- #1493 longestSubarray.py
- #1503 getLastMoment.py
- #1514 maxProbability.py
- #1535 getWinner.py
- #1545 findKthBit.py
- #1557 findSmallestSetOfVertices.py
- #1561 maxCoins.py
- #1574 findLengthOfShortestSubarray.py
- #1578 minCost.py
- #1584 minCostConnectPoints.py
- #1593 maxUniqueSplit.py
- #1615 maximalNetworkRank.py
- #1637 maxWidthOfVerticalArea.py
- #1647 minDeletions.py
- #1721 swapNodes.py
- #1759 countHomogenous.py
- #1823 findTheWinner.py
- #1828 countPoints.py
- #1829 getMaximumXor.py
- #1861 rotateTheBox.py
- #1975 maxMatrixSum.py
- #2001 interchangableRectangles.py
- #2018 placeWordInCrossword.py
- #2024 maxConsecutiveAnswers.py
- #2028 missingRolls.py
- #2044 countMaxOrSubsets.py
- #2054 maxTwoEvents.py
- #2063 countVowels.py
- #2064 minimizedMaximum.py
- #2070 maximumBeauty.py
- #2090 getAverages.py
- #2095 deleteMiddle.py
- #2101 maximumDetonation.py
- #2104 subArrayRanges.py
- #2109 addSpaces.py
- #2115 findAllRecipes.py
- #2120 executionInstructions.py
- #2130 pairSum.py
- #2140 mostPoints.py
- #2221 triangularSum.py
- #2257 countUnguarded.py
- #2265 averageOfSubtree.py
- #2305 distributeCookies.py
- #2326 spiralMatrix.py
- #2337 canChange.py
- #2352 equalPairs.py
- #2369 validPartition.py
- #2415 reverseOddLevels.py
- #2461 maximumSubarraySum.py
- #2462 totalCost.py
- #2466 countGoodStrings.py
- #2483 bestClosingTime.py
- #2497 maxStarSum.py
- #2501 longestSquareStreak.py
- #2516 takeCharacters.py
- #2530 maxKelements.py
- #2542 maxScore.py
- #2554 maxCount.py
- #2563 countFairPairs.py
- #2583 kthLargestLevelSum.py
- #2593 findScore.py
- #2597 beautifulSubsets.py
- #2616 minimizeMax.py
- #2623 memoize.js
- #2640 findPrefixScore.py
- #2641 replaceValueInTree.py
- #2657 findThePrefixCommonArray.py
- #2658 findMaxFish.py
- #2679 matrixSum.py
- #2680 maximumOr.py
- #2684 maxMoves.py
- #2707 minExtraChar.py
- #2712 minimumCost.py
- #2718 matrixSumQueries.py
- #2731 sumDistance.py
- #2735 minCost.py
- #2740 findValueOfPartition.py
- #2749 makeTheIntegerZero.py
- #2779 maximumBeauty.py
- #2785 sortVowels.py
- #2849 isReachableAtTime.py
- #2914 minChanges.py
- #2924 findChampion.py
- #2938 minimumSteps.py
- #2971 largestPerimeter.py
- #2981 maximumLength.py
- #3011 canSortArray.py
- #3163 compressedString.py
- #3179 valueAfterKSeconds.py
- #3217 modifiedList.py
- #3243 shortestDistanceAfterQueries.py
- #3254 resultsArray.py
- #3355 isZeroArray.py
- #3356 minZeroArray.py
- #6393 maxStrength.py
- #6425 longestSemiRepetitiveSubstring.py
- #6431 doesValidArrayExist.py
- #6432 countCompleteComponents.py
- #6433 maxMoves.py
- #6441 punishmentNumber.py
- #6468 countServers.py
- #6895 longestString.py
- #6898 minimizeConcatenatedLength.py
- #23 mergeKLists.py
- #25 reverseKGroup.py
- #30 findSubstring.py
- #32 longestValidParentheses.py
- #42 trap.py
- #68 fullJustify.py
- #135 candy.py
- #224 calculate.py
- #239 maxSlidingWindow.py
- #297 Codec.py
- #403 canCross.py
- #664 strangePrinter.py
- #810 xorGame.py
- #864 shortestPathAllKeys.py
- #920 numMusicPlaylists.py
- #1187 makeArrayIncreasing.py
- #1220 countVowelPermutation.py
- #1359 countOrders.py
- #1383 maxPerformance.py
- #1406 stoneGameIII.py
- #1489 findCriticalAndPseudoCriticalEdges.py
- #1547 minCost.py
- #1569 numOfWays.py
- #1575 countRoutes.py
- #1601 maximumRequests.py
- #1671 minimumMountainRemovals.py
- #2272 largestVariance.py
- #2290 minimumObstacles.py
- #2448 minCost.py
- #2551 putMarbles.py
- #2642 Graph.py
- #2699 modifiedGraphEdges.py
- #2707 minExtraChar.py
- #2709 canTraverseAllPairs.py
- #2713 maxIncreasingCells.py
- #2719 count.py
- #2732 goodSubsetofBinaryMatrix.py