Skip to main content

Array Patterns

2- Pointer

  1. 2-Sum
  2. Rearrange the array in alternating positive and negative items
  3. 3-Sum
  4. 4-Sum

Sliding Window

While both the two-pointer and sliding window techniques use two pointers to traverse a data structure, they are not exactly the same. Sliding window is a specific type of two-pointer technique where the pointers define a window of elements, and this window is “slid” through the data structure.

Prefix Sum

  1. Longest subarray with a sum = K
  2. Count of subarrays with a given sum
  3. Largest subarray with a sum = 0

Matrix

  1. Set Matrix to zero
  2. Rotate a Matrix by 90, 180 and 270
  3. Spiral Traversal

Merge Sort

  1. Count Inversion
  2. Reverse pairs

Algorithms

  1. Dutch national flag
  2. Moors Voting Algorithm
  3. Moors Voting Algorithm(n/3)
  4. Kadane’s Algorithm with printing
  5. Next Permutation