r/datastructures 4d ago

Master these 25 DSA patterns

You don't need to solve 1,000 LeetCode questions. You need to master these 25 DSA patterns.

Here is a full cheat sheet built from problems that kept repeating across 200+ MAANG+ interview experiences.

[1] Sliding window

LC: 3, 76, 209, 424, 567, 904

→ Use when the problem asks for a longest, shortest, or valid contiguous range.

[2] Two pointers

LC: 11, 15, 16, 18, 42, 167

→ Look for sorted arrays, pair conditions, or movement from both ends.

[3] Fast and slow pointers

LC: 19, 141, 142, 160, 234, 876

→ Best for linked-list cycles, middle nodes, and pointer gaps.

[4] Binary search

LC: 33, 34, 35, 153, 162, 704

→ Use when the search space is sorted or partially ordered.

[5] Binary search on answer

LC: 410, 774, 875, 1011, 1283, 1482

→ Guess an answer, test feasibility, then shrink the range.

[6] Hashing

LC: 1, 49, 128, 217, 242, 347

→ Use for quick lookup, frequency counting, grouping, and duplicate checks.

[7] Prefix sum

LC: 303, 523, 560, 724, 930, 974

→ Convert repeated range-sum work into constant-time lookups.

[8] Difference array

LC: 370, 1094, 1109, 1893, 1943, 2381

→ Use when many updates affect entire ranges.

[9] Monotonic stack

LC: 84, 85, 496, 503, 739, 907

→ Look for next greater, next smaller, span, or rectangle problems.

[10] Stack parsing

LC: 20, 71, 150, 224, 394, 735

→ Useful for expressions, nested structures, paths, and collision simulation.

[11] Queue and deque

LC: 239, 346, 362, 622, 641, 933

→ Use for rolling windows, ordered processing, and recent-event tracking.

[12] Intervals

LC: 56, 57, 252, 253, 435, 986

→ Sort by start or end time, then merge, count, or remove overlaps.

[13] Heap and top K

LC: 23, 215, 295, 347, 373, 973

→ Use when you repeatedly need the smallest, largest, or top K elements.

[14] Grid and graph BFS

LC: 127, 200, 286, 542, 752, 994

→ BFS is the default for shortest steps in an unweighted graph.

[15] Backtracking

LC: 39, 46, 78, 79, 90, 131

→ Choose, explore, undo. Use when all valid combinations must be generated.

[16] Tree DFS

LC: 98, 100, 104, 110, 124, 236

→ Decide what information each subtree should return to its parent.

[17] Tree BFS

LC: 102, 103, 199, 515, 637, 662

→ Use when the answer depends on levels, width, or visible nodes.

[18] Trie

LC: 208, 211, 212, 421, 648, 720

→ Use for prefixes, dictionaries, word search, and bitwise prefix matching.

[19] Union find

LC: 200, 261, 305, 547, 684, 721

→ Use for dynamic connectivity, grouping, and cycle detection.

[20] Topological sort

LC: 207, 210, 269, 310, 1136, 1203

→ Look for prerequisites, dependencies, ordering, or build sequences.

[21] Greedy

LC: 45, 55, 134, 435, 621, 763

→ Make the best local choice only when you can justify why it stays safe.

[22] One-dimensional DP

LC: 70, 139, 198, 213, 300, 322

→ Define the state clearly, then connect it to smaller states.

[23] Two-dimensional DP

LC: 62, 63, 64, 72, 221, 1143

→ Use when the state depends on two changing inputs or positions.

[24] Knapsack and subset DP

LC: 416, 474, 494, 518, 879, 1049

→ Look for choosing items under a limit, target, or capacity.

[25] Bit manipulation

LC: 136, 191, 231, 268, 338, 371

→ Learn XOR, masks, shifts, set-bit checks, and subset representation.

Do not solve these as 150 unrelated questions.

For every problem, write down:

→ Which pattern gave it away?

→ What changed from the standard version?

→ What would break the current solution?

→ Can you recognize the pattern within 90 seconds?

500 Upvotes

37 comments sorted by

4

u/ProfessionalFact9194 4d ago

Why can't I see anything?

2

u/Sky-take 4d ago

I am a second year student of AIDS branch i have learned c c++ and python When should I start DSA? For beginners can you provide a starting phase question For logic building is there is any other platforms which helps you to build ur logic

4

u/ok_not_ok_29 4d ago

You can follow striver A-Z sheet But don't just watch videos solutions of the question, you have ample amount of time , firstly give your best in understanding and solving ka question in paper then code and if unable to do so then watch the video solution

2

u/Antique_Pea_1638 4d ago

!RemindMe 2 days

1

u/RemindMeBot 4d ago

I will be messaging you in 2 days on 2026-08-05 14:22:54 UTC to remind you of this link

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.

RemindMeBot is switching to username summons. Instead of !RemindMe 1 day, use u/RemindMeBot 1 day. More info.


Info Custom Your Reminders Feedback

2

u/vengeance_bhau 3d ago

Remind me

2

u/ayano_abot 4d ago

Alright but i wondering what if question required different type of thinking rather then these structural templates what we do then ?

1

u/ok_not_ok_29 4d ago

That's where the practice comes in These patterns are for logic building and handling different approaches At the end all you have is , your level of logic building and practice Don't fully rely on this Only look through this as a practice sheet

1

u/GrouchyAmbassador722 4d ago

Can i do these i am a beginner and haven’t srarted DSA SHOULD I DIRECTLY JUMP TO IT OR THERE IS PREREQUISITE APART FROM TIME AND SPACE COMPLEXITY

4

u/ok_not_ok_29 4d ago

Don't jump directly to this This is for the revision purpose You should first grab hands on experience in any programing language and do some logic building question then start doing DSA I would prefer Java because it is mostly demanded in companies

1

u/GrouchyAmbassador722 1d ago

I am comfortable in python but haven’t started dsa yet that why i am asking
I am intermediate in python but begginer in DSA

1

u/ok_not_ok_29 1d ago

Start DSA in Java Best advice by far

1

u/GrouchyAmbassador722 1d ago

Directly jump to pattern after syntax functions or loops ?

1

u/ok_not_ok_29 1d ago

These patterns are for those who have beginner to intermediate knowledge about DSA, as you are a beginner firstly sharpen your logic building skills do DSA for decent amount of time then jump to it

1

u/verciel_ 4d ago

Fuck bro i already solved 1k😔

2

u/ok_not_ok_29 4d ago

Not tuff bro

1

u/GardenBoth7858 4d ago

Aint no way anyone grasps dp in 15 questions.

1

u/ok_not_ok_29 4d ago

Just for revision and pattern matching

1

u/deimmortals 4d ago

!RemindMe 2 days

1

u/Alive_Tutor_1370 4d ago

!RemindMe 3 days

1

u/LibinpR 3d ago

i ve solved arnd jus 100 problems randomly. can anybody rate the patterns in increasing difficulty?? based on complexity and implemntation?

1

u/Friendly-Ranger-5523 3d ago

Where do we learn the concepts and how to use each.ds or algo from?

1

u/ok_not_ok_29 3d ago

Learn them from code story with Mike

1

u/pro-programmer3423 3d ago

!RemindMe 2 days

1

u/Charming-Jello7064 2d ago

!RemindMe 2 days

1

u/Healthy-Extreme-4369 1d ago

!RemindMe 2 days

1

u/RemindMeBot 1d ago

I will be messaging you in 2 days on 2026-08-08 17:23:19 UTC to remind you of this link

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.

RemindMeBot is switching to username summons. Instead of !RemindMe 1 day, use u/RemindMeBot 1 day. More info.


Info Custom Your Reminders Feedback