Skip to content
mccornet edited this page Jul 23, 2021 · 15 revisions

Leetcode Problems

These are my solutions to leetcode problems.

Most of the problems started by following this list:
https://seanprashad.com/leetcode-patterns/

Problem Classifications

Arrays

Fast & Slow Pointers

Two Pointers

Dynamic Programming

Binary Search

Problem Approach

If input array is sorted then

  • Binary search
  • Two pointers

If asked for all permutations/subsets then

  • Backtracking

If given a tree then

  • DFS
  • BFS

If given a graph then

  • DFS
  • BFS

If given a linked list then

  • Two pointers

If recursion is banned then

  • Stack

If must solve in-place then

  • Swap corresponding values
  • Store one or more different values in the same pointer

If asked for maximum/minumum subarray/subset/options then

  • Dynamic programming

If asked for top/least K items then

  • Heap

If asked for common strings then

  • Map
  • Trie

Else

  • Map/Set for O(1) time & O(n) space
  • Sort input for O(nlogn) time and O(1) space

Clone this wiki locally