0% found this document useful (0 votes)
16 views4 pages

Download the Cheat Sheet

The document provides a cheat sheet for array problem-solving techniques, outlining various methods such as Two-Pointer, Sliding Window, and Hashing, along with their use cases and common problems associated with each technique. It also covers additional techniques like Prefix Sum, Binary Search, Greedy Algorithms, Sorting, Stack, Backtracking, Dynamic Programming, Union-Find, and Kadane's Algorithm. Each technique is accompanied by specific scenarios where it is applicable and examples of problems that can be solved using it.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

Download the Cheat Sheet

The document provides a cheat sheet for array problem-solving techniques, outlining various methods such as Two-Pointer, Sliding Window, and Hashing, along with their use cases and common problems associated with each technique. It also covers additional techniques like Prefix Sum, Binary Search, Greedy Algorithms, Sorting, Stack, Backtracking, Dynamic Programming, Union-Find, and Kadane's Algorithm. Each technique is accompanied by specific scenarios where it is applicable and examples of problems that can be solved using it.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Array Problem Solving Techniques Cheat Sheet

1. Two-Pointer Technique

Use When:

- The array is sorted (or can be sorted).

- You're trying to find pairs or triplets with a specific condition (e.g., sum = target).

Common Problems:

- Two Sum II

- 3Sum, 4Sum

- Remove Duplicates

- Container With Most Water

- Trapping Rain Water

2. Sliding Window

Use When:

- You need to find subarrays (contiguous) that satisfy a condition.

Common Problems:

- Maximum Subarray

- Longest Substring Without Repeating Characters

- Minimum Size Subarray Sum

- Permutation in String

3. Hashing (HashMap / HashSet)

Use When:

- You need to track frequencies or seen values.

Common Problems:

- Two Sum

- Subarray Sum Equals K

- Group Anagrams
Array Problem Solving Techniques Cheat Sheet

- Longest Consecutive Sequence

- Contains Duplicate

4. Prefix Sum / Cumulative Sum

Use When:

- You're working with range queries or need subarray sums efficiently.

Common Problems:

- Subarray Sum Equals K

- Range Sum Query

- Find Pivot Index

5. Binary Search

Use When:

- Array is sorted or has a search space to exploit.

Common Problems:

- Search in Rotated Sorted Array

- Find Minimum in Rotated Sorted Array

- Median of Two Sorted Arrays

- Koko Eating Bananas

6. Greedy Algorithms

Use When:

- The problem involves optimization and local choices.

Common Problems:

- Jump Game

- Gas Station

- Burst Balloons
Array Problem Solving Techniques Cheat Sheet

- Candy Distribution

7. Sorting

Use When:

- Order matters or to simplify logic.

Common Problems:

- Merge Intervals

- Meeting Rooms

- Sort Colors

- Relative Sort Array

8. Stack/Monotonic Stack

Use When:

- Need to find next/prev greater/smaller elements.

Common Problems:

- Daily Temperatures

- Next Greater Element

- Trapping Rain Water

- Largest Rectangle in Histogram

9. Backtracking / DFS

Use When:

- All combinations/permutations are required.

Common Problems:

- Subsets

- Combination Sum

- Permutations
Array Problem Solving Techniques Cheat Sheet

- Word Search

10. Dynamic Programming

Use When:

- The problem has overlapping subproblems and optimal substructure.

Common Problems:

- House Robber

- Maximum Subarray

- Longest Increasing Subsequence

- Partition Equal Subset Sum

11. Union-Find (Disjoint Set Union)

Use When:

- Connected components or cycles are involved.

Common Problems:

- Number of Connected Components

- Redundant Connection

- Accounts Merge

12. Kadane's Algorithm

Use When:

- Finding maximum sum subarray.

Common Problems:

- Maximum Subarray

- Maximum Product Subarray

You might also like