- Two Sum - Use hashmap to hash each value, but before hashing check, if the difference has already been hashed.
- Best Time to Buy and Sell Stock - Find local min and search for local max, sliding window;
- Contains Duplicate - Use sets operation then compare lengths
- Product of Array Except Self - make two passes, first in order, second in reverse, to compute products. (you will need the prefix & suffix to compute these values)
- Maximum Subarray - Pattern: prev subarray cant be negative, dynamic programming: compute max sum for each prefix
- Maximum Product Subarray - Dynamic programming problem, keeping track of max and min product.
- Find Minimum in Rotated Sorted Array - Use binary search to determine you’re in the LHS or RHS of the sorted sub array.
- Search in Rotated Sorted Array - Use binary search determine if you’re in the LHS or RHS and handle them
- 3 Sum - One loop and perform 2 sum on each iteration
- Container With Most Water - Shrinking Window: use pointers favouring the biggest height
- Sum of Two Integers - add bit by bit, be mindful of carry, after adding, if carry is still 1, then add it as well.
- Number of 1 Bits - Use bitwise & 1. Incrementing the count value of 1.
- Counting Bits - Write binary values of 0-16 to find pattern; res[i] = res[i - offset], where offset is the biggest power of 2 <= I;
- Missing Number - Compute expected sum - real sum;
- Reverse Bits - reverse each of 32 bits;
- Climbing Stairs - Bottom-up approach. Compute for the last 2 which always have just […1,1] ways. Then work backwards by adding the dp[i+1] + dp[i+2]
- Coin Change - Bottom-up approach(tabulation). Compute coins for amount 1→ n, then compare (amount-coin). Can also do it with a Top-down approach(memoization).
- Longest Increasing Subsequence - solve from RHS, as nums[-1] only has 1 subsequence use this to solve for the rest taking the max subsequence from DP[]
- Longest Common Subsequence - Bottom-up approach. Use 2d matrix e.g abc0 x abc0, and fill each index with values to allow matrix[0][0] hold the value. (if match move diagonally else move sideways right & down)
- Word Break Problem - Bottom-up approach. Dp with the last value of True. Update dp[i] by checking if the range(s[i]:i+offset) can form a word in the word dictionary.
- Combination Sum - Recursive backtracking with Decision Tree - find all combinations possible with arr[i] and without arr[i]
- House Robber - DP problem, The last 2 houses have a sum of their actual value as they don't have adjacent houses that meet the requirement.
- House Robber II - Perform house robberI on a slice of the arrays. arr1 = remove first index, arr2= remove last index, arr3= only first index
- Decode Ways - DFS + memoization. 2 decisions to be made at every step.
- Unique Paths - DFS + memoization. A more efficient way is to Iteratively calculate each row checking values at the bottom + right and then returning the row at 0. (bottom-up approach)
- Jump Game - Iterate backwards to see if the index can reach the “end” variable. If so update the end variable to that position. If end == 0 then it was possible.
- Clone Graph
- Course Schedule
- Pacific Atlantic Water Flow
- Number of Islands
- Longest Consecutive Sequence
- Alien Dictionary (Leetcode Premium)
- Graph Valid Tree (Leetcode Premium)
- Number of Connected Components in an Undirected Graph (Leetcode Premium)
- Insert Interval
- Merge Intervals
- Non-overlapping Intervals
- Meeting Rooms (Leetcode Premium)
- Meeting Rooms II (Leetcode Premium)
- Reverse a Linked List- iterate through maintaining cur and prev; recursively reverse pointers. (return head)
- Detect Cycle in a Linked List
- Merge Two Sorted Lists
- Merge K Sorted Lists - Traverse both lists and create a new list while comparing value each node
- Remove Nth Node From End Of List
- Reorder List
- Longest Substring Without Repeating Characters
- Longest Repeating Character Replacement
- Minimum Window Substring
- Valid Anagram
- Group Anagrams
- Valid Parentheses
- Valid Palindrome
- Longest Palindromic Substring
- Palindromic Substrings
- Encode and Decode Strings (Leetcode Premium)
- Maximum Depth of Binary Tree
- Same Tree
- Invert/Flip Binary Tree
- Binary Tree Maximum Path Sum
- Binary Tree Level Order Traversal
- Serialize and Deserialize Binary Tree
- Subtree of Another Tree
- Construct Binary Tree from Preorder and Inorder Traversal
- Validate Binary Search Tree
- Kth Smallest Element in a BST
- Lowest Common Ancestor of BST
- Implement Trie (Prefix Tree)
- Add and Search Word
- Word Search II
- Subarray Equal to K - use prefix sum