Leetcode Patterns

by Sean Prashad

A collection of 178 questions grouped by pattern to help you prepare for coding interviews.

Feedback

About

In 2019, as a broke college student who couldn't afford premium interview resources, I spent countless hours searching for free materials and teaching myself React to build Leetcode Patterns.

I believe everyone deserves access to high-quality interview material - regardless of their financial situation. It's why I chose to make this website free and open source.

Best of luck on your journey!

Sean

Helpful Tips

Based on the problem constraints, use these heuristics to identify possible approaches when unsure.

ConditionApproach
Arrays & Strings
If input array is sortedBinary search, Two pointers
If need O(1) lookupHash table, Hash set
If must solve in-placeSwap corresponding values, Store multiple values in the same pointer
If asked for common stringsMap, Trie
If asked to count bits or use XORBit manipulation
Subarrays & Sequences
If asked for max/min subarray/subsetDynamic programming, Sliding window
If asked for sliding window max/minMonotonic queue
If asked for next greater/smaller elementMonotonic stack
If need range sum/frequency queriesPrefix sum, Binary indexed tree, Segment tree
Trees & Graphs
If given a treeDFS, BFS
If given a graphDFS, BFS, Union-Find
If given a matrixBFS, DFS, Dynamic programming
If asked for connectivity/groupingUnion-Find, DFS
If asked for ordering/schedulingTopological sort
Linked Lists & Stacks
If given a linked listTwo pointers
If recursion is bannedStack
Sorting & Intervals
If asked for top/least K itemsHeap, Quickselect, Bucket sort
If asked to merge sorted lists/intervalsMerge sort, Heap
If asked for overlapping intervalsSorting, Sweep line
If given a stream of dataHeap, Design
Optimization
If asked for all permutations/subsetsBacktracking
If need to count/divide optimallyGreedy, Dynamic programming
General
ElseMap/Set for O(1) time & O(n) space, Sort input for O(nlogn) time and O(1) space