Algorithms  List  For FAANGM

Algorithms List For FAANGM

Key Algorithms You Need to Know for FAANGM

Here is a categorized list of algorithms and techniques that are essential for cracking interviews at FAANGM (Facebook/Meta, Amazon, Apple, Netflix, Google, Microsoft) companies. These algorithms are grouped based on data structures and problem types, along with tips for identifying when to use them.


1. Arrays

Key Algorithms and Techniques

  1. Two-Pointer Technique

    • When to use: When the problem involves finding pairs, triplets, or partitions in sorted/unsorted arrays.

    • Examples:

      • Finding a pair with a given sum.

      • Sorting colors (Dutch National Flag problem).

  2. Sliding Window

    • When to use: When the problem involves subarrays or substrings with specific properties (e.g., fixed/variable length).

    • Examples:

      • Maximum sum subarray of size K.

      • Longest substring with at most K distinct characters.

  3. Kadane's Algorithm

    • When to use: To find the maximum sum subarray.

    • Examples: Maximum subarray problem.

  4. Merge Intervals

    • When to use: When the problem involves overlapping intervals or intervals manipulation.

    • Examples:

      • Merging overlapping intervals.

      • Meeting room scheduling.

  5. Cyclic Sort

    • When to use: When dealing with problems involving permutations of numbers from 1 to N.

    • Examples:

      • Finding missing numbers.

      • Detecting duplicates.


2. Strings

Key Algorithms and Techniques

  1. Knuth-Morris-Pratt (KMP) Algorithm

    • When to use: To find patterns in strings efficiently.

    • Examples: String search, substring match.

  2. Rabin-Karp Algorithm

    • When to use: When dealing with multiple pattern matching or substring search.

    • Examples: Detecting plagiarism.

  3. Sliding Window (for Strings)

    • When to use: When dealing with substring problems.

    • Examples:

      • Longest substring without repeating characters.

      • Minimum window substring.

  4. Trie (Prefix Tree)

    • When to use: Problems involving prefixes or dictionaries.

    • Examples:

      • Word search in a grid.

      • Autocomplete systems.

  5. Z Algorithm

    • When to use: For pattern matching and finding repetitions in strings.

    • Examples: Substring search, string compression.


3. Linked Lists

Key Algorithms and Techniques

  1. Reversal

    • When to use: Reversing parts of a linked list.

    • Examples: Reverse nodes in groups.

  2. Fast and Slow Pointers

    • When to use: Detecting cycles or finding the middle element.

    • Examples:

      • Detecting a cycle in a linked list.

      • Finding the starting point of the cycle.

  3. Merge Sort

    • When to use: Sorting a linked list.

    • Examples: Sorting a singly or doubly linked list.


4. Trees

Key Algorithms and Techniques

  1. Binary Search Tree (BST) Traversals

    • When to use: Searching, inserting, or deleting elements.

    • Examples: Validating a BST.

  2. Depth-First Search (DFS)

    • When to use: To explore all paths or nodes in a tree.

    • Examples:

      • Finding the maximum depth of a binary tree.

      • Path sum problems.

  3. Breadth-First Search (BFS)

    • When to use: Level-order traversal or shortest path.

    • Examples: Zigzag level order traversal.

  4. Lowest Common Ancestor (LCA)

    • When to use: Problems involving ancestor relationships.

    • Examples: Finding the LCA of two nodes.

  5. Segment Trees and Fenwick Trees

    • When to use: When dealing with range queries or updates.

    • Examples: Range sum or minimum queries.


5. Graphs

Key Algorithms and Techniques

  1. Depth-First Search (DFS)

    • When to use: When exploring paths or checking connectivity.

    • Examples:

      • Detecting cycles.

      • Connected components.

  2. Breadth-First Search (BFS)

    • When to use: Finding the shortest path in an unweighted graph.

    • Examples: Word ladder problem.

  3. Dijkstra’s Algorithm

    • When to use: Finding the shortest path in a weighted graph.

    • Examples: Navigation systems.

  4. Kruskal's and Prim's Algorithms

    • When to use: Finding the minimum spanning tree.

    • Examples: Network connection problems.

  5. Topological Sort

    • When to use: For problems involving dependencies.

    • Examples: Course scheduling.

  6. Union-Find

    • When to use: Problems involving connected components or cycle detection.

    • Examples: Redundant connection in a graph.


6. Dynamic Programming

Key Algorithms and Techniques

  1. Knapsack Problems

    • When to use: Resource optimization problems.

    • Examples:

      • Subset sum.

      • Partition problem.

  2. Longest Common Subsequence (LCS)

    • When to use: Comparing sequences.

    • Examples: Text similarity.

  3. Matrix Chain Multiplication

    • When to use: Optimal parenthesization problems.

    • Examples: Multiplying matrices with minimum cost.

  4. Floyd-Warshall Algorithm

    • When to use: All-pairs shortest paths.

    • Examples: Finding shortest paths in a graph.

  5. Bellman-Ford Algorithm

    • When to use: Shortest paths in a graph with negative weights.

    • Examples: Currency arbitrage.


7. Recursion and Backtracking

Key Algorithms and Techniques

  1. Subset and Permutation Generation

    • When to use: Generating combinations or permutations.

    • Examples:

      • Subsets of a set.

      • Permutations of a string.

  2. N-Queens Problem

    • When to use: Placing objects under constraints.

    • Examples: Chessboard problems.

  3. Sudoku Solver

    • When to use: Solving grid-based puzzles.

    • Examples: Sudoku, crossword puzzles.


8. Greedy Algorithms

Key Algorithms and Techniques

  1. Activity Selection

    • When to use: Maximizing the count of non-overlapping intervals.

    • Examples: Interval scheduling.

  2. Huffman Encoding

    • When to use: Data compression.

    • Examples: Compressing text files.

  3. Dijkstra's Algorithm

    • When to use: When greedily finding the shortest path works.

How to Identify the Algorithm from the Problem

  1. Subarray/Subsequence Problems: Use Sliding Window or Kadane's Algorithm.

  2. Pattern Search in Strings: Use KMP or Trie.

  3. Cycle Detection in Graphs: Use DFS or Union-Find.

  4. Matrix Problems: Use Dynamic Programming or DFS/BFS.

  5. Optimal Resource Allocation: Use Knapsack or Greedy Algorithms.

  6. Dependency Resolution: Use Topological Sort.


Master these algorithms and practice solving problems on platforms like LeetCode, HackerRank, and Codeforces to build a solid foundation for FAANGM interviews! 🚀