• DFS ✅ 2024-10-12
  • BFS ✅ 2024-10-12
  • Arrays algorithms ✅ 2024-10-26
  • Binary trees ✅ 2024-10-26
  • Stacks ✅ 2024-10-26
  • Dynamic Programming ✅ 2024-11-26

Arrays:

Let’s start with some challenging array-based problems that deal with sorting, searching, and manipulation.

  1. leetcodearrays Leetcode 238 - Product of Array Except Self: ✅ 2024-10-10
  2. leetcodearrays Leetcode 41 - First Missing Positive: ✅ 2024-10-10
  3. leetcodearrays Leetcode 560 - Subarray Sum Equals K: ✅ 2024-10-11

Stacks:

Stacks are great for problems involving balanced parentheses, monotonic stacks, or evaluating expressions.

  1. leetcodestackLeetcode 20 - Valid Parentheses: ✅ 2024-10-11
  2. leetcodestack Next Greater Element ✅ 2024-10-11
  3. leetcodestack 84 Daily Temperatures ✅ 2024-10-11
  4. leetcodestackEvaluate Reverse Polish Notation ✅ 2024-10-11
  5. leetcodestack Min Stack ✅ 2024-10-12
  6. leetcodestack `Remove K Digits ✅ 2024-10-11
  7. leetcodestack Largest Rectangle in Histogram ✅ 2024-10-12
  8. leetcodestack Asteroid Collision ✅ 2024-10-12
  9. leetcodestack Basic Calculator (I, II, III) ✅ 2024-10-12 K digits with stack: when we found a digit, we see if the digit on the left (that is the top of the stack) is larger, so we can pop that digit and replace with the current one, we do as match as K. If at the end of the loop we still have count < k, we pop

Binary search isn’t just limited to searching in sorted arrays. It can be used in various forms to solve interval and range-related problems.

  1. leetcodebinarysearchLeetcode 33 - Search in Rotated Sorted Array: ✅ 2024-10-13
  2. leetcodebinarysearch Leetcode 81 - Search in Rotated Sorted Array II: ✅ 2024-10-28
  3. leetcodebinarysearch Leetcode 287 - Find the Duplicate Number: ✅ 2024-10-28

Binary Trees:

Binary trees will build on your traversal skills while introducing problems around paths, depth, and tree properties.

  1. Leetcode 105 - Construct Binary Tree from Preorder and Inorder Traversal:

  2. Leetcode 114 - Flatten Binary Tree to Linked List:

  3. Leetcode 543 - Diameter of Binary Tree:

ExerciseLevelStrategySolution
Leetcode 238 - Product of Array except selfMediumPrefix and suffix arrayMultiply prefix and suffix array except i
Leetcode 241 - First missing positiveHardReorderingPut val in index val-1 in the array. Traverse array, first unmatched index is solution
Leetcode 560 - Subarray sum equals KMediumHashtable + prefix arrayTraverse the array and put current prefix sum in the hash. If hash contains prefix sum - k, that’s a solution
Leetcode 34 Find first and last index in a sorted arrayMediumBinary searchFind the element via binary search and expand
Leetcode 33 Search in rotated arrayMediumBinary searchCheck if the first half if sorted, if the element is in the first half range, update right, else left
else if the second half is sorted, check if the element is in range and update r, else update l
Leetcode 81 Search in rotated array IIMediumBinary SearchThe duplication makes possible to have situation where you have nums[l] nums[mid] nums[r] and impossible to distinguish. Since none of them is the solution, move l by 1 to restrict the scan
Leetcode 852 Peak Index in a Mountain ArrayMediumBinary SearchCheck if arr[mid] > arr[mid+1], if it is, go left, because you are on downard slope on the right, else go right
Leetcode 153. Find minimum in Rotated Sorted ArrayMediumBinary SearchAfter sorting [4,5,6,7,1,2,3] the array will be split in a larger left part [4,5,6,7] and a smaller right part [1,2,3]. If the right part is sorted, then the minimum is either in the left part or at mid (rotation might occur just before). If the right part is unsorted, the minimum is there
Leetcode 658 Find K closest element in Binary searchMediumBinary SearchFind the leftmost location of the window by restrict binary search [0, len(arr)-k]. Return arr[l:l+k]. Compare array[mid]-x with array[mid+k] - x
Leetcode 875 Koko Eating BananasMediumBinary SearchSet speed min 1, max = max(pile), use binary search and exit if time exceed hours