Find video link at my YouTube channel
Or from the Sheet 1 of this Google Sheet
# | Title | Solution | Code | Time | Space | Difficulty | Tags | Video |
---|---|---|---|---|---|---|---|---|
0001 | 2 Sum problem | Check all the combinations by looping Map, if itโs complement (target - element) and exists then return the indices of the current element and the complement. | C++ Java Python | O(n) | O(1) | Easy | Hash Table Heap | ๐บ |
0011 | Container With Most Water | Two pointer approach from left and right side. Increment the left pointer if height is less than right otherwise decrement the right pointer. If current holding capacity is more than previous update. | Python | O(n) | O(1) | Medium | Array Two pointer | |
0021 | Merge Two Sorted Lists | Algo The strategy here uses a temporary dummy node as the start of the result list. The pointer Tail always points to the last node in the result list, so appending new nodes is easy. The dummy node gives the tail something to point to initially when the result list is empty. | C++ | O(m+n) | O(1) | Easy | Linked List | ๐บ |
0021 | Merge Two Sorted Lists | The strategy here uses a temporary dummy node as the start of the result list. The pointer Tail always points to the last node in the result list, so appending new nodes is easy.The dummy node gives the tail something to point to initially when the result list is empty.This dummy node is efficient, since it is only temporary, and it is allocated in the stack.The loop proceeds, removing one node from either โaโ or โbโ, and adding it to the tail | Java | O(n) | O(1) | Easy | Linked List | ๐บ |
0027 | Remove Element | Two pointers for counting valid nos and swapping | Java Python | O(n) | O(1) | Easy | Array Two Pointers | ๐บ |
0044 | Wildcard Matching | Use bottom-up approach, when '?' detected copy value from upper diagonal cell and when '*' detected copy value from previous coloumn same row or previous row same coloumn | Python | O(n*n) | O(n*n) | Hard | DP on Regex problem | |
0045 | Jump Game II | newEnd = max(newEnd, i+nums[i]) | C++ | O(n) | O(1) | Hard | Array Greedy | ๐บ |
0053 | Maximum Subarray | Parse array and save the best solution at each step | Java Python | O(n) | O(1) | Easy | Array Dynamic Programming | ๐บ |
0055 | Jump Game | Iterate from last index and check if we can reach there from current index or not | Python | O(n) | O(1) | Medium | Array Greedy | ๐บ |
0062 | Unique Paths (Total no of unique paths in m x n matrix) | As the first element in each row will always be 1, so maintaining one row is enough to reach bottom-right corner of the grid | Java Python | O(n) | O(1) | Medium | Array Dynamic Programming | |
0070 | Climbing Stairs | steps[n]=steps[n-1]+steps[n-2]. | C++ Python | O(n) | O(1) | Easy | Dynamic Programming | ๐บ |
0072 | Edit Distance | minDis(i,j)=min(minDis(i-1,j),minDis(i,j-1),minDis(i-1,j-1))+1; | Java | O(m*n) | O(m*n) | Hard | String Dynamic programming | |
0073 | Set Matrix Zeroes | Use the first cell of every row and column as a flag. This flag would determine whether a row or column has been set to zero. | C++ Python | O(m*n) | O(1) | Medium | Array | ๐บ |
0075 | Sort an array of 0โs 1โs 2โs without using extra space or sorting algo | the logic is to count total number of 0's, 1's and 2's int the list and starting from beginning first append total 0's then total 1's and then 2's | Java Python | O(n) | O(1) | Medium | Array | ๐บ |
0100 | Same Tree | Check isSame(node.left) and isSame(root.right) | Java | O(n) | O(h) | Easy | Tree Depth-first-Search | ๐บ |
0100 | Same Tree | Check isSame(node.left) and isSame(root.right) | Java Python | O(n) | O(h) | Easy | Tree Depth-first-Search | ๐บ |
0101 | Symmetric Tree | Check if left.left==right.right and left.right==right.left | Java Python | O(n) | O(h) | Easy | Tree Depth-first-Search Breadth-first-Search | ๐บ |
0104 | Maximum Depth of Binary Tree | Depth = 1 + Max(depth of left, depth of right) | Java | O(n) | O(h) | Easy | Tree Depth-first-Search | ๐บ |
0121 | Best time to buy and sell stock | Minimize Cost price and Maximise Profit , if the current value minus the minimum is the new maximum profit | Java Python | O(n) | O(1) | Easy | Array Dynamic Programming | ๐บ |
0142 | Linked List Cycle II | Floydโs Cycle detection algorithm | Java | O(n) | O(1) | Medium | Linked List Two pointers | |
0198 | House Robber | Keep track of max money by figuring out whether to loot the current house or not | Python | O(n) | O(1) | Easy | Dynamic Programming | ๐บ |
0200 | Number of islands | Merging adjacent lands, and the merging is done recursively | Java | O(nโm) | O(1) | Medium | Depth-First Search Breadth-First Search | ๐บ |
0268 | Missing Number | Assuming that XOR is a constant-time operation, this algorithm does constant work on nn iterations, so the runtime is overall linear | C++ Java | O(n) | O(1) | Easy | Array Math BitManipulation | |
0283 | Move Zeroes | Two pointers for counting valid nos and swapping | Java | O(n) | O(1) | Easy | Array Two Pointers | ๐บ |
0287 | Find duplicate in array of N+1 numbers | Find the cycle using slow and fast pointer | Java | O(n) | O(1) | Medium | Array Two Pointers | |
0300 | Longest Increasing Subsequence | when next element in array is greater than previous element, dp[i]=maximum(dp[j]+1,dp[i]) | Java | O(n*m) | O(n) | Medium | Binary Search Dynamic Programming | |
0451 | Sort Characters By Frequency | LeetCode Github | Java Python | O(n) | O(n) | Medium | Hash Table Heap | |
0509 | Fibonacci Number | Storing the value of two previous number and updating them | Java | O(n) | O(1) | Easy | Array | ๐บ |
0647 | Palindromic Substrings | Extend from center, 2 function call for odd and even palindromes | Java Python | O(n^2) | O(1) | Medium | String Dynamic Programming | ๐บ |
0695 | Max Area of Island | Apply DFS on the Gird by exploring every square connected to it 4-directionally, total number of squares explored will be the area of that connected shape. | C++ | O(RโC) | O(RโC) | Medium | Depth-First-Search | |
0876 | Middle of the Linked List | Find the length of given linked list and then traverse from root till one less than half of linked list length and print the next node to current node | Java | O(n) | O(1) | Easy | Linked List | |
0983 | Minimum Cost For Tickets | Here dp(i) is the cost to travel from day days[i] to the end of the plan. if days[j] < days[i] + 1 then j1=j. if days[j] < days[i] + 7 then j=j7. if days[j] < days[i] + 30 then j=j30 . dp(i)=min(dp(j1)+costs[0],dp(j7)+costs[1],dp(j30)+costs[2]) | Java | O(n) | O(n) | Medium | Dynamic Programming | ๐บ |
1347 | Minimum Number of Steps to Make Two Strings Anagram | Add 1 for char in s and remove 1 for char in t | Java Python | O(n+m) | O(1) | Medium | Hash Table Heap | ๐บ |
1352 | Product of the Last K Numbers | Add new element to list by multiplying it with previous number and return arr[n-1]/arr[n-k-1] | Python | O(1) | O(1) | Medium | Array Design | ๐บ |
Format
0000 | Ques name | Algo | Java | O() | O() | Easy | Category | ๐บ |
---|---|---|---|---|---|---|---|---|
0000 | Ques name | Algo | Java | O() | O() | Easy | Category | ๐บ |