leetcode

LeetCode Cheat Sheet – 50 Problems

  • Misc, Python

Concepts

Sliding Window

Give n element and k window size, try to get max sum.

Bindary Search

  • Only work when data is sorted

Step:

  1. Use the left and right element as 2 pointers
  2. Find the middle pointer between 2 pointers
  3. Compare the middle element to search term
  4. If middle > search term, replace left pointer with middle pointer + 1
  5. If middle < search term, replace right pointer with middle pointer – 1

Hash Table

  • hash function
  • collusion

collusion handling

  • chaining: make each key point to a linked list, -> easy, never get full, use extra space and search O(N)
  • open addressing: if key exists, probe until available -> more computation(probing), can get full, better performance

If number of keys is unknown, use chain; other wise use open addressing.

probe methods

  • linear probing: probe to next slot
  • quadratic probing
  • double hashing

Read More »LeetCode Cheat Sheet – 50 Problems