Must-Know LeetCode Patterns for Newbies

1. Two Pointers

2. Hashing

3.Sorting

4. Sliding Window

5. Monotonic Stack

6. Binary Search

7. Prefix Sum

8. Greedy Algorithms

9. Heap/Priority Queue

10. Queue

Basic information about the pattern

1. Two Pointers

In this approach, we take two indices as i and j, and we process the elements from left to right.

2. Hashing

In this approach, we take key-value pairs to count the frequency of elements.

3. Sorting

In this approach, we rearrange the elements in ascending or descending order to solve basic and advanced problems.

4. Sliding Window

In this approach, we find a fixed-size window and move it to solve complex problems related to subarrays and substrings.

5. Monotonic Stack

In this approach, we maintain a sequence of elements in a specific order (increasing or decreasing) to find the next greater or smaller element.

This approach works on sorted elements. In this approach, the search space is divided into left and right halves based on the middle value.

7. Prefix Sum

In this approach, the previous element and the new element are added to solve the problem efficiently. This is useful for subarrays and can also be called a cumulative sum.

8. Greedy Algorithms

This approach aims to find a global optimal solution by making a series of locally optimal choices.

9. Heap/Priority Queue

In this approach, we find the kth largest or kth smallest element by maintaining a priority sequence.

"In the next blog, we will explore each pattern in detail."