- Open the Problems Directory
- Check the this readme and refer to the code which is either written in python or c++ or c
-
Split the array into two partions such that the sum of both partitons is the same. Constraint : You can swap one element from one partition to another.
-
On a 2D plane, there are n points with integer coordinates points[i] = [xi, yi]. Return the minimum time in seconds to visit all the points in the order given by points.
You can move according to these rules:
In 1 second, you can either: move vertically by one unit, move horizontally by one unit, or move diagonally sqrt(2) units (in other words, move one unit vertically then one unit horizontally in 1 second). You have to visit the points in the same order as they appear in the array. You are allowed to pass through points that appear later in the order, but these do not count as visits.
-
Iterative knapsack problem solution.
-
Hamiltonian cycle
-
Find middle elemnt in a linked list]
-
Anagram Solution : two strings with words. Go through each word and check if anagrams can be formed. If not then minimum modification that is needed to make it into an anagram
-
License plate formatting : https://leetcode.com/problems/license-key-formatting/
-
Longest Absolute File Path : https://leetcode.com/problems/longest-absolute-file-path/
-
Next Permutation : https://leetcode.com/problems/next-permutation/
-
Memoized fibonacci
-
Count the number of paths in the grid from one location to another.
-
Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
-
Combination sum : https://leetcode.com/problems/combination-sum/
-
Maximum Subarray : https://leetcode.com/problems/maximum-subarray/
-
canSum : Function to check if a target sum be calculated given an array of numbers. Dp problem
-
climbing stairs : combination of 1's and 2's to reach nth step
-
is subsequence : Is s a subsequence of t
-
Sell and buy stocks wit htransaction fee : https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee/
-
Integer Break : https://leetcode.com/problems/integer-break/
-
Maxdepth of a tree
-
symmetric tree
-
Balanced Binary Tree
-
FLatten Binary Tree to linked list
-
Third Maximum number in an array
-
Kth largest number in an array
-
Find Duplicate Number (Only one number is repeated in the list/array)
-
Minimum Operations to Make the Array Increasing : https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/
-
Invert Binary Tree
-
Monotone array
-
Number of Susequences
-
Count The number of Teams : https://leetcode.com/problems/count-number-of-teams/ (Backtracked)
-
Count The number of Teams : https://leetcode.com/problems/count-number-of-teams/ (Iterative)
-
Validate a binary Tree https://leetcode.com/problems/validate-binary-search-tree/
-
Range Sum of a Binary Tree
-
Two sum : Hashmap Solution https://leetcode.com/problems/two-sum/
-
Good Nodes : https://leetcode.com/problems/count-good-nodes-in-binary-tree/
-
Adding two lists
-
Checking if a linked list is a palindrome
-
Ones and zeroes https://leetcode.com/problems/ones-and-zeroes/
-
Longest paranthesis substring
-
Toeplitz Matrix : A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same elements.
-
Spiral Matrix : https://leetcode.com/problems/spiral-matrix/
-
First Unique Character : https://leetcode.com/problems/first-unique-character-in-a-string/
-
Sort by frequency : https://leetcode.com/problems/sort-characters-by-frequency/
-
Sort increasing order : https://leetcode.com/problems/sort-array-by-increasing-frequency/
-
Genearte Parenthesis : https://leetcode.com/problems/generate-parentheses/
-
Longest Substring Match : https://leetcode.com/problems/longest-substring-without-repeating-characters/
-
Add two linked lists : https://leetcode.com/problems/add-two-numbers-ii/
-
Trim BST : https://leetcode.com/problems/trim-a-binary-search-tree/
-
Remove instances of an element : https://leetcode.com/problems/remove-element/
-
Relative Sorting : https://leetcode.com/problems/relative-sort-array/
-
K Closest Points to Origin : https://leetcode.com/problems/k-closest-points-to-origin/
-
Top K frequent items : priority_queue https://leetcode.com/problems/top-k-frequent-elements/
-
All elements in two binary tree : https://leetcode.com/problems/all-elements-in-two-binary-search-trees/
-
Rotate String : https://leetcode.com/problems/rotate-string/
-
Majority Element II : https://leetcode.com/problems/majority-element-ii/
-
Count Vowel Strings : https://leetcode.com/problems/count-sorted-vowel-strings/
-
Remove K digits
-
Minimum cost path : https://leetcode.com/problems/minimum-path-sum/
-
Permutations : https://leetcode.com/problems/permutations/
-
Paths from source to destination : https://leetcode.com/problems/all-paths-from-source-to-target/
-
Group Anagrams : https://leetcode.com/problems/group-anagrams/
-
Intersection in linked list : https://leetcode.com/problems/intersection-of-two-linked-lists/
-
Construct binary tree using preorder and inorder lists : https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/
-
Hamming distance : <>
-
Find Peak Element : https://leetcode.com/problems/find-peak-element/
-
Mountain array : https://leetcode.com/problems/peak-index-in-a-mountain-array/
-
Delete a node without using head : https://leetcode.com/problems/delete-node-in-a-linked-list/
-
Number of 1 bits : https://leetcode.com/problems/number-of-1-bits/
-
Minimum cost to reach the top : https://leetcode.com/problems/min-cost-climbing-stairs/
-
Sum of all left Leaves : https://leetcode.com/problems/sum-of-left-leaves/
-
Reverse Substrings Between Each Pair of Parentheses : https://leetcode.com/problems/reverse-substrings-between-each-pair-of-parentheses/
-
Distribute Candies : https://leetcode.com/problems/distribute-candies/
-
N Queens problem : https://leetcode.com/problems/n-queens/
-
word break : https://leetcode.com/problems/word-break/
-
Kth Smallest Element in a BST : https://leetcode.com/problems/kth-smallest-element-in-a-bst/
-
Minimum Absolute difference in bst : <>
-
Split a balanced string : https://leetcode.com/problems/split-a-string-in-balanced-strings/
-
Find common characters in words : https://leetcode.com/problems/find-common-characters/
-
Square of a sorted array : https://leetcode.com/problems/squares-of-a-sorted-array/
-
Heigh Checker : https://leetcode.com/problems/height-checker/
-
Search Insert Position : https://leetcode.com/problems/search-insert-position/
-
Number of provinces : https://leetcode.com/problems/number-of-provinces/
-
Pangram : https://leetcode.com/problems/check-if-the-sentence-is-pangram/
-
Palindrome Number : https://leetcode.com/problems/palindrome-number/
-
Add two strings : <>
-
Minimum Number of Days to Eat N Oranges : https://leetcode.com/problems/minimum-number-of-days-to-eat-n-oranges/
-
Binary Watch : https://leetcode.com/problems/binary-watch/
-
Prison Cells after N days : https://leetcode.com/problems/prison-cells-after-n-days/
-
Student Attendance Record I : https://leetcode.com/problems/student-attendance-record-i/
-
Power of Two : https://leetcode.com/problems/power-of-two/
-
Open Lock : https://leetcode.com/problems/open-the-lock/
-
Max area island : https://leetcode.com/problems/max-area-of-island/
-
Two sum BST : https://leetcode.com/problems/two-sum-iv-input-is-a-bst/
-
GC of two strings : https://leetcode.com/problems/greatest-common-divisor-of-strings/
-
Reverse Vowels : https://leetcode.com/problems/reverse-vowels-of-a-string/
-
Maximum value at each level in a Binary tree : https://leetcode.com/problems/find-largest-value-in-each-tree-row/
-
Longest Consecutive Sequence : https://leetcode.com/problems/longest-consecutive-sequence/
-
Minimum cost climbinf stairs
-
Unique Paths II : https://leetcode.com/problems/unique-paths-ii/
-
House Robber : https://leetcode.com/problems/house-robber/
-
Minimum Number of Vertices to Reach All Nodes : https://leetcode.com/problems/minimum-number-of-vertices-to-reach-all-nodes/
-
Divisor Game : https://leetcode.com/problems/divisor-game/
-
Left view of tree
-
Rod cutting : maximize product
-
Sum of left view
-
Convert BS to sorted Linked List
-
Find the City With the Smallest Number of Neighbors at a Threshold Distance : https://leetcode.com/problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/
-
Count Numbers with Unique Digits : https://leetcode.com/problems/count-numbers-with-unique-digits/
-
Palindrome pairs
-
Minimum Number Units oN a Truck
-
Min jums to reach n-1 position :
-
Flip an image : https://leetcode.com/problems/flipping-an-image/
-
Leaf similar trees : https://leetcode.com/problems/leaf-similar-trees/
-
Remove outer parantheses : https://leetcode.com/problems/remove-outermost-parentheses/
-
Combination sum-ii : https://leetcode.com/problems/combination-sum-ii/
-
Find bottom tree left leaf : https://leetcode.com/problems/find-bottom-left-tree-value/
-
Filter Restaurants by Vegan-Friendly, Price and Distance : https://leetcode.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance/
-
House robber II : https://leetcode.com/problems/house-robber-ii/
-
Combination Sum 3 : https://leetcode.com/problems/combination-sum-iii/
-
Remove Covered Intervals : https://leetcode.com/problems/remove-covered-intervals/
-
Longest Word in Dictionary through Deleting : https://leetcode.com/problems/longest-word-in-dictionary-through-deleting/
-
Path with maximum gold : https://leetcode.com/problems/path-with-maximum-gold/
-
Word Search : https://leetcode.com/problems/word-search/
-
Minimum Insertion Steps to Make a String Palindrome : https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome/
-
Odd Even List : https://leetcode.com/problems/odd-even-linked-list/
-
Boats to save people : https://leetcode.com/problems/boats-to-save-people/
- equalarr.cpp (c++ STL approach)
- min-path-2d-plane.cpp
- knapsack.cpp (c++ STL approach)
- hamiltonian.cpp (c++ STL approach)
- midelelist.c
- anagram.c
- LicenseFormat.py
- LongestAbsoluteFilePath.py
- nextpermutation.cpp (c++ STL approach)
- fibdp.cpp
- countpathfromtoplefttobottomright.cpp (No memoization)
- searchindexpostion.cpp
- combinationsum.cpp
- maximumsubarray.cpp (DP approach c++)
- Dynamic_Programming/Memoization/canSum.cpp (Dp memoization)
- Dynamic_Programming/Memoization/climbingstairs.cpp (Dp memoization)
- issubsequence.cpp (Brute Force approach)
- sellstockwithtransaction.py (Iterative)
- IntegerBreak.cpp : Backtracking solution
- Tree/maxdepth.cpp : Recursive
- Tree/symmetrictree.cpp : Recursive
- Tree/balancedbintree.cpp : Recursive
- Tree/flattentree.cpp : Recursive
- Array/thirdMax.cpp
- Array/kthlargestarray.cpp
- Array/FindDuplicateNumber.cpp
- Array/MinimumOperationsToMakeIncArray.cpp
- Tree/invertTree.cpp
- Array/MonotoneArray.cpp : Iterative
- Array/numberofsubsequences.cpp
- Backtracking/CountTheNumberOfTeams.cpp
- Array/CountTheNumberOfTeams.cpp
- Tree/validateBinaryTree.cpp
- Tree/RangeSumBST.cpp (inorder approach)
- Array/twosum.cpp
- Tree/goodnodes.cpp
- LinkedList/addingtwolists.cpp
- LinkedList/palindromelist.cpp
- Recursion/oneszeroes.cpp
- Array/longestparanthesismatch.cpp (Brute force approach)
- Array/Toeplitzmat.cpp
- Array/spiralmatrix.cpp
- Array/firstuniquecharacter.cpp
- String/sortbyfreq.cpp
- Array/sortincfrq.cpp
- Backtracking/generateParenthesis.cpp
- String/longestsubstring.cpp
- LinkedList/add-linked-list-ii.cpp
- Tree/trimBST.cpp
- Array/removeInstance.cpp
- Array/relativeSorting.cpp
- Array/kclosestpintstoorigin.cpp
- Array/Topkfreqitems.cpp
- Tree/allelementsin2binarytree.cpp
- String/rotateString.cpp
- Array/majorityElements.cpp
- Backtracking/countVowelStrings.cpp
- Backtracking/removeKDigits.cpp
- Dynamic_Programming/minpathcost.cpp
- Backtracking/all_permutations.cpp
- Backtracking/pathsfromsourcetodestination.cpp
- String/groupAnagrams.cpp
- LinkedList/intersectionLinkedList.cpp
- Tree/constructBinaryTreePI.cpp
- Binary/hammingDistance.cpp
- Array/findPeakElement.cpp
- Array/MountainArray.cpp
- LinkedList/deleteNodeWithoutHead.cpp
- Binary/numberOf1Bits.cpp
- Array/minCostToReachTop.cpp
- Tree/sumOfLeftLeaves.cpp
- String/reverseSubstringsBetweenEachParentheses.cpp
- Array/aliceCandies.py
- Backtracking/NQueens.cpp
- DynamicProgramming/Memoization/wordBreak.cpp
- Tree/kthSmallestElementBST.cpp
- Tree/minAbsDiffBST.cpp
- String/balacedString.cpp
- String/findCommonCharacters.cpp
- Array/squareSortedArray.cpp
- Array/heightChecker.cpp
- Array/searchInsertPosition.cpp
- Backtracking/provinces.cpp
- String/pangram.cpp
- palindromeNumber.cpp
- String/addTwoStrings.cpp
- Recursion/fruits.cpp
- Backtracking/binaryWatch.cpp
- Array/prisonCellsAfterNdays.cpp
- String/StudentAttendanceRecord.cpp
- Recursion/powerOfTwo.cpp
- Leetcode_challenges/Day4/openLock.cpp
- Leetcode_challenges/Day4/maxAreaIsland.cpp
- Tree/twoSumBST.cpp
- String/gcdOfStrings.cpp
- String/reverseVowels.cpp
- Tree/maxValInLevel.cpp
- Leetcode_challenges/Day6/longestconsecutivesequence.cpp
- Array/3sum.cpp
- Leetcode_challenges/Day7/minCostClimbingStairs.cpp
- Backtracking/uniquePathsII.cpp
- Array/houserobber.cpp
- Graph/minNumberOfNodesNeededTOVisitAllNodes.cpp
- divisorGame.cpp
- Tree/leftViewOfTree.cpp
- Dynamic_Programming/maxProductRodCutting.cpp
- Tree/sumOfLeftView.cpp
- Tree/bstTOSortedLinkedList.cpp
- Graph/smallestNuberOfNeighBoursAtThresholdDistance.cpp
- Backtracking/countUniqueDigitNumbers.cpp
- Leetcode_challenge/Day13/palindromePairs.cpp
- Leetcode_challenge/Day13/minNumberOfUnitsTruck.cpp
- Greedy/minJumps2.cpp
- Array/flipImage.py
- Tree/leafSimilar.cpp
- String/removeOuterParentheses.cpp
- Backtracking/combinationSumii.cpp
- Tree/findBottomTreeLeftLeaf.cpp
- Array/filterRestaurant.cpp
- Dynamic_Programming/houseRobber-ii.cpp
- Backtracking/combinationSum3.cpp
- Array/removeCoveredIntervals.cpp
- String/longestWordDictionaryThroughDeletion.cpp
- Graph/goldRunner.cpp
- Graph/wordSearch.cpp
- String/minInsertionsToMakePalindrome.cpp
- LinkedList/oddEvenList.cpp
- Greedy/boatsToSavePeople.cpp
-
Backtracking
-
Dynamic Programming
- If you identify that a problem can be solved using DP
- Try to create a backtrack function that calculates the correct answer.
- Try to avoid the redundant arguments, minimize the range of possible values of function arguments
- Try to optimize the time complexity of one function call
- Memoize the values and don't calculate the same things twice.
- Key points to remember of Dp :
- Optimal substructure : Optimal solution to a problem involves optimal solutions to sub-problems.
- Overlapping Sub-problems : Subproblems once computed can be stored in a table for further use. This saves the time needed to compute the same sub-problems again and again.
- Exponential runtime can be converted/brought down to polynomial runtime.