Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Grokking the coding interview equivalent leetcode problems


I liked the way Grokking the coding interview organized problems into learnable patterns. However, the course is expensive and the majority of the time the problems are copy-pasted from leetcode. As the explanations on leetcode are usually just as good, the course really boils down to being a glorified curated list of leetcode problems.

So below I made a list of leetcode problems that are as close to grokking problems as possible.

Pattern: Sliding Window

Pattern: Two Pointers

Pattern: Fast & Slow pointers

Pattern: Merge Intervals

Pattern: Cyclic Sort

Pattern: In-place Reversal of a LinkedList

Pattern: Tree Breadth First Search

Pattern: Tree Depth First Search

Pattern: Two Heaps

Pattern: Subsets

Pattern: Modified Binary Search

Pattern: Bitwise XOR

Pattern: Top 'K' elements

Pattern: K-way merge

Pattern: 0/1 Knapsack

Pattern: Topological Sort


Copy link

BoxiangG commented Feb 5, 2022
This is the question for cyclic sort, the third from the end

Copy link

iamricks commented Feb 20, 2022

Thank you for this list

Copy link

gaurishg commented Feb 23, 2022

For Pattern: Merge Intervals, I think this is the missing problem: Array Manipulation (Hacker Rank)

Copy link

iamricks commented Feb 24, 2022

Under Pattern: Two Pointers is a sliding window problem, a bit confusing when trying to study by topic

Copy link

carrickkv2 commented Feb 26, 2022

@AntonBelski the modified version does not work.

Copy link

blake-whitman commented Feb 27, 2022

The misc question is already included in the "Top K Elements" section. Great list!

Copy link

rwalle61 commented Mar 11, 2022

Thanks for the list!

I think Pattern: Two Pointers first grok question "Pair with Target Sum" is more like Two Sum II than Two Sum because the input is sorted. In Two Sum, the input is not sorted, so a Two Pointer solution (sort first) is slower than the O(N) caching solution. In Two Sum II, the input is sorted, and we're can't use extra space, so the Two Pointer solution makes sense




Copy link

tonyz0212 commented Mar 16, 2022

Awesome list!

Copy link

mayafrog commented Mar 18, 2022

Under Pattern: Two Pointers is a sliding window problem, a bit confusing when trying to study by topic

Sliding window is only valid if all the values are positive I think.

Copy link

khatiba commented Apr 25, 2022

For 0/1 Knapsack: Minimum Subset Sum Difference:
Maybe a significant difference is that the array lengths should be len(nums)/2 🤷

Copy link

Locne55 commented May 3, 2022

thanks for this.

Copy link

AntonBelski commented May 4, 2022

Last problem for Pattern: Modified Binary Search similar to this -

Copy link

ShreyanGoswami commented Jun 10, 2022

Missing problem for Modified Binary Search is similar to

Copy link

necusjz commented Jun 13, 2022

For Pattern: Merge Intervals, I think this is the missing problem: Array Manipulation (Hacker Rank)

Nice catch! The corresponding problem in LeetCode should be

Copy link

ParthPandey2611 commented Jun 16, 2022

Thanks for sharing!

Copy link

shazib2022skipq commented Jul 23, 2022

Thanks a lot.

Copy link

dyu222 commented Jul 30, 2022

^^ here is the first problem is islands

Copy link

shan4993 commented Aug 1, 2022

Merge Intervals is missing a problem: Conflicting Appointments (medium) ->

Copy link

shan4993 commented Aug 3, 2022

Not an exact match but close enough.

Ceiling of a Number (medium) ->

Copy link

khatiba commented Aug 3, 2022

@i-zanis topological orderings are not unique right?

Copy link

swarnabhK commented Aug 4, 2022

Thanks for the list! Can anyone point me out to some resources where I can learn these patterns?

Copy link

unrelentingfox commented Aug 4, 2022

The topological sort 1st and 3rd question is exactly the same as a solution in Grokking. I converted the List to return int[] instead however when I test it on leetcode, the output is not in the same order. Does anyone know something?

The direction of the dependency graph in the leetcode problem is in reverse. For each edge, the first value is a course, the second value is it's pre-requisite. To determine the order in which to take all of the courses, you traverse from pre-requisite -> course.

So from your code change this:
int parent = edges[i][0], child = edges[i][1]
to this:
int parent = edges[i][1], child = edges[i][0]

Copy link

ayushjainid commented Aug 6, 2022

Not all heroes..

Copy link

shan4993 commented Aug 6, 2022

For Tree BST (right after zig zag) should be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment