Skip to content

xingvoong/14-patterns

Repository files navigation

14 Patterns to Ace Any Coding Interview Question

14 Patterns to Ace Any Coding Interview Question

1. Sliding Window

  • Maximum sum subarray of size ‘K’ (easy)
  • Longest substring with ‘K’ distinct characters (medium)
  • String anagrams (hard)

2. Two Pointers or Iterators

  • Squaring a sorted array (easy)
  • Triplets that sum to zero (medium)
  • Comparing strings that contain backspaces (medium)

3. Fast and Slow Pointers

  • Linked List Cycle (easy)
  • Palindrome Linked List (medium)
  • Cycle in a Circular Array (hard)

4. Merge Intervals

  • Intervals Intersection (medium)
  • Maximum CPU Load (hard)

5. Cyclic sort

  • Find the Missing Number (easy)
  • Find the Smallest Missing Positive Number (medium)

6. In-place reversal of linked list

  • Reverse a sub list (medium)
  • Reverse every K-element sub-list (medium)
    • Recursive
    • Iterative

7. Tree BFS, use a queue

Use a queue

  • Binary Tree Level Order Traversal (easy)
    • Recursive
    • Iterative
  • Zigzag Traversal (medium)
  • Minimum Depth of Binary Tree (Easy)
  • Average of Levels in Binary Tree (Easy)
  • Cousins in Binary Tree (Easy)
  • Binary Tree Level Order Traversal II (Medium)
  • Binary Tree Vertical Order Traversal (Medium)
  • N-ary Tree Level Order Traversal (Medium)

8. Tree DFS, use a stack

  • Sum of Path Numbers (medium)

    • recursive
    • Iterative
  • All Paths for a Sum (medium)

    • recursive
    • Iterative

9. 2 Heaps

  • Find the Median of a Number Stream (medium)

10. Subsets

  • Subsets With Duplicates (easy)
  • String Permutations by changing case (medium)

11. Modify Binary Search

  • Binary Search
  • Infinite Array (medium)
  • Search in a Sorted Array of Unknown Size

12. Top K elements

  • Top ‘K’ Frequent Numbers (medium)
  • Kth Largest Element in an Array
  • K Closest Points to Origin

13: k ways merge

  • Merge K Sorted Lists
  • smallest sum k pair
  • kth-smallest-element-in-a-sorted-matrix/

14: Topological sort

Learn and solve tree traversal

  • Learn recursive solutions first
  • Learn iterative solution later

Acknowledgements

About

14 Patterns to Ace Any Coding Interview Question

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published