Skip to content

Latest commit

 

History

History
130 lines (99 loc) · 9.35 KB

README.md

File metadata and controls

130 lines (99 loc) · 9.35 KB

Updating list of LeetCode I've solved.

My note - Guide to LeetCoding

Array


Binary

  • 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;

Dynamic Programming

  • 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.

Graph


Interval


Linked List


Matrix


String


Tree


Heap

Extra Practice

  • Subarray Equal to K - use prefix sum