Skip to content

Top 20 coding patterns

  • by

The top 20 coding patterns enhance our “ability to map a new problem to an already known problem.”

  • Sliding-Window
  • Islands-Matrix-Traversal
  • Two-Pointers
  • Fast-Slow-Pointers
  • Merge-Intervals
  • Cyclic-Sort
  • In-place-Reversal-of-a-LinkedList
  • Tree-Breadth-First-Search
  • Tree-Depth-First-Search
  • Two-Heaps
  • Subsets
  • Modified-Binary-Search
  • Bitwise-XOR
  • Top-‘K-Elements
  • K-way-Merge
  • Topological-Sort
  • Unbounded-Knapsack
  • Fibonacci-Numbers
  • Palindromic-Subsequence
  • Longest-Common-Substring

Here are the 20 coding patterns:

1. Sliding Window:

This algorithmic technique is used when handling the input data in a specific window size.

2. Islands (Matrix Traversal)

This pattern describes all the efficient ways of traversing a matrix (or 2D array).

3. Two Pointers

This technique uses two pointers to iterate input data. Generally, both pointers move in the opposite direction at a constant interval.

4. Fast & Slow Pointers

Also known as Hare & Tortoise algorithm. This technique uses two pointers that traverse the input data at different speeds.

5. Merge Intervals

This technique is used to deal with overlapping intervals.

6. Cyclic Sort

Use this technique to solve array problems where the input data lies within a fixed range.

7. In-place Reversal of a LinkedList

This technique describes an efficient way to reverse the links between a set of nodes of a LinkedList. Often, the constraint is that we need to do this in place, i.e., using the existing node objects without using extra memory.

8. Tree Breadth-First Search

This technique solves problems involving traversing trees or graphs in a breadth-first search manner.

9. Tree Depth First Search

This technique solves problems involving traversing trees or graphs in a depth-first search manner.

10. Two Heaps

In many problems, we are given a set of elements that can be divided into two parts. We are interested in knowing the smallest element in one part and the biggest element in the other part. As the name suggests, this technique uses a Min-Heap to find the smallest element and a Max-Heap to find the biggest element.

11. Subsets

Use this technique when the problem asks to deal with permutations or combinations of a set of elements.

12. Modified Binary Search

Use this technique to search a sorted set of elements efficiently.

13. Bitwise XOR

This technique uses the XOR operator to manipulate bits to solve problems.

14. Top ‘K’ Elements

This technique is used to find the top/smallest/frequently occurring 1K’ elements in a set.

15. K-way Merge

This technique helps us solve problems that involve a list of sorted arrays.

16. Topological Sort

Use this technique to find a linear ordering of elements that have dependencies on each other.

17. Unbounded Knapsack

This technique is used to solve optimization problems. Use this technique to select elements that give maximum profit from a given set with a limitation on capacity and that each element can only be picked once.

18. Fibonacci Numbers

Use this technique to solve problems that follow the Fibonacci numbers sequence, i.e., every subsequent number is calculated from the last few numbers.

19. Palindromic Subsequence

This technique is used to solve optimization problems related to palindromic sequences or strings.

20. Longest Common Substring

Use this technique to find the optimal part of a string/sequence or set of strings/sequences.

Leave a Reply

Your email address will not be published. Required fields are marked *