Coder Social home page Coder Social logo

leetcode-patterns's Introduction

Algo questions or leetcode problem patterns

#LeetCode #Patterns #LeetcodePatterns #DataStructures

Preparation links:

Pattern Links:

Best problem patterns:

  • Binary Search(Arrays) - binary search the answer and see if it works, binary search the prefix sum to find longest sub in an array;
  • Sliding Window(Arrays, Strings, Hash Tables) - input data in a specific window size, increase the size while condition is met, move the start after;
  • BFS/DFS - subsets, queue, topological sort, tree/graph/matrix traversal;
  • Two Pointers, Fast & Slow Pointer(Arrays, Strings) - move opposite direction at a constant interval, traverse input data on different speeds;
  • Union Find or Disjoint Set Data-structure;
  • Recursion/Memoization/Backtracking;
  • Dynamic Programming;
  • Graphs(shortest path, minimum spanning tree, A*)
  • Sorting(HeapSort, Bucket Sort, QuickSelect, QuickSort);
  • Greedy;

Best Data Structures:

  • Hash Table;
  • Prefix sum;
  • Heap(Priority Queue, Binary);
  • Trie(Prefix Tree, Strings Tree);
  • DSU(Disjoint Set Data-structure);
  • Tree(Binary, AVL, Red-Black, Statistic Order);
  • Stack/Queue;
  • Deque;
  • Segment Tree(Fenwick Tree or Binary Indexed Tree/BIT);

Extended problem patterns:

  • Monotonic Stack;
  • Islands(Matrix, Queue) - flood fill, efficient way of traversing traversing a matrix or 2d array;
  • Merge intervals(Arrays, Heap) - deal with overlapping intervals;
  • Topological Sort (Array, HashTable, Queue, Graph) - linear ordering of elements that have dependencies on each other;
  • Top K elements(Array, Heap, Queue) - find top/smallest/frequently occurring K elements in a set;
  • Two Heaps(Heap, Array) - set of elements can be divided into two parts, smallest element in one part(Min-Heap) and biggest in the other part(Max-Heap);
  • Cyclic Sort(Arrays) - input data lies within a fixed range;
  • 0/1 Knapsack(Array, HashTable) - dynamic programming to solve optimization problems, given a set of items(weight + value), determine the number of each item to include in a collection so that the total weight <= limit and the total value is as large as possible;
  • Subsets(Queue, Array, String) - deal with permutations or combinations of a set of elements;
  • Fibonacci Numbers(Array, HashTable) - every subsequent number is calculated from the last few numbers;
  • Palindromic Subsequence(Array, HashTable) - dynamic programming on lps(longest palindromic 1, 2) solve optimization problems related to palindromic sequences or strings;
  • Longest Common Substring(Array, HashTable) - optimal is dynamic programming(1) or less efficient binsearch the length + hashtable with rolling hash(2);
  • K-way merge(Array, Queue, Heap) - solve problems that involve a list of sorted arrays;
  • Math (sieve, log)
  • Bitwise XOR(Array, Bits) - manipulate bits to solve problems, a ^ a = 0;

Almost never used data-structures, but fancy:

  • Treap, Rope, Cartesian Tree;
  • Splay Tree, B Tree, B+ Tree, K-D tree;
  • Heap(Binomial, Fibonacci);
  • Skip List;
  • Suffix Array/Suffix Tree;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.