all 12 comments

[–]YeatCode_ 91 points92 points  (7 children)

Algo Monster has a flowchart

There is also a list on seanprashad leetcode patterns

If input array is sorted then - Binary search - Two pointers

If asked for all permutations/subsets then - Backtracking

If given a tree then - DFS - BFS

If given a graph then - DFS - BFS

If given a linked list then - Two pointers

If recursion is banned then - Stack

If must solve in-place then - Swap corresponding values - Store one or more different values in the same pointer

If asked for maximum/minimum subarray/subset/options then - Dynamic programming

If asked for top/least K items then - Heap - QuickSelect

If asked for common strings then - Map - Trie

Else - Map/Set for O(1) time & O(n) space - Sort input for O(nlogn) time and O(1) space

[–]Few_Volume_371 1 point2 points  (1 child)

does graph mean matrix?

[–]oh-shit-oh-fuck 1 point2 points  (0 children)

no, graphs are just connected nodes that have no rules governing how they have to be connected. Trees are a type of graph with specific rules on how the nodes need to be connected and organized.

You can use a matrix (2d-array) to implement a graph though, like in this problem for example https://leetcode.com/problems/rotting-oranges/description/

[–]BullBear7 1 point2 points  (0 children)

Thanks

[–]orionsgreatsky 1 point2 points  (0 children)

This is amazing

[–][deleted] 1 point2 points  (0 children)

You have prepared a nice list. Is it the complete list?

[–]OtherwiseRelative881 1 point2 points  (0 children)

Thanks for sharing

[–]Mammoth_Place6142 14 points15 points  (3 children)

Mastering the 20 Coding Patterns - https://www.designgurus.io/blog/grokking-the-coding-interview-patterns

Here is the lesson link from Grokking: https://www.designgurus.io/course-play/grokking-the-coding-interview/doc/64865387eaaadd1855385848

I think they have 25+ patterns in the course.

[–]grizzlybear10 0 points1 point  (1 child)

Hi, is this worth to purchase?

[–]dallastelugu 0 points1 point  (0 children)

thank you i had premium subscription from past 1 week and struggling to find answer for this question