0% found this document useful (0 votes)
139 views3 pages

DSA CheatSheet Patterns

The document outlines various problem-solving patterns used in data structures and algorithms, including Sliding Window, Two Pointer, Prefix Sum, Binary Search, and Hashing/Frequency Maps. Each pattern is associated with specific types of problems and key strategies for implementation. The document serves as a cheat sheet for efficiently tackling common algorithmic challenges.

Uploaded by

Yogesh Sharma
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)
139 views3 pages

DSA CheatSheet Patterns

The document outlines various problem-solving patterns used in data structures and algorithms, including Sliding Window, Two Pointer, Prefix Sum, Binary Search, and Hashing/Frequency Maps. Each pattern is associated with specific types of problems and key strategies for implementation. The document serves as a cheat sheet for efficiently tackling common algorithmic challenges.

Uploaded by

Yogesh Sharma
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/ 3

DSA Cheat Sheet & Problem Patterns

Sliding Window Pattern

Used in problems involving subarrays or substrings.

Fixed Window:

- Maximum sum subarray of size K

- Max/Min of all subarrays of size K

- First negative number in every window of size K

Variable Window:

- Longest substring with K unique characters

- Longest subarray with sum at most K

- Minimum window substring

Key Idea: Expand and shrink window with two pointers.

Two Pointer Pattern

Used when array or string is sorted or needs linear pass from both ends.

Problems:

- Two sum (sorted)

- Container with most water

- Remove duplicates from sorted array

- 3Sum problem

Key Idea: Move left/right pointers based on condition.

Prefix Sum Pattern


DSA Cheat Sheet & Problem Patterns

Useful for range sum problems.

Problems:

- Subarray sum equals K

- Equilibrium index

- Count number of subarrays with given sum

Key Idea: Precompute prefix sum array or use hashmap to store running sums.

Binary Search Pattern

Used on sorted arrays or answers.

Problems:

- Binary search in array

- Find peak element

- Search in rotated sorted array

- Koko Eating Bananas (search on answers)

Key Idea: Divide and conquer. Adjust low/high pointers.

Hashing / Frequency Maps

Used to count or track elements.

Problems:

- Two sum (unsorted)

- Longest substring without repeating characters

- Group anagrams
DSA Cheat Sheet & Problem Patterns

Key Idea: Use unordered_map to track frequency or index.

You might also like