Skip to content

Instantly share code, notes, and snippets.

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

GROKKING NOTES

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

Misc

@BoxiangG
Copy link

BoxiangG commented Feb 5, 2022

https://leetcode.com/problems/set-mismatch/
This is the question for cyclic sort, the third from the end

@iamricks
Copy link

iamricks commented Feb 20, 2022

Thank you for this list

@gaurishg
Copy link

gaurishg commented Feb 23, 2022

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

@iamricks
Copy link

iamricks commented Feb 24, 2022

Under Pattern: Two Pointers https://leetcode.com/problems/subarray-product-less-than-k/ is a sliding window problem, a bit confusing when trying to study by topic

@carrickkv2
Copy link

carrickkv2 commented Feb 26, 2022

@AntonBelski the modified version does not work.

@blake-whitman
Copy link

blake-whitman commented Feb 27, 2022

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

@rwalle61
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

image

image

image

@tonyz0212
Copy link

tonyz0212 commented Mar 16, 2022

Awesome list!

@mayafrog
Copy link

mayafrog commented Mar 18, 2022

Under Pattern: Two Pointers https://leetcode.com/problems/subarray-product-less-than-k/ 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.

@khatiba
Copy link

khatiba commented Apr 25, 2022

For 0/1 Knapsack: Minimum Subset Sum Difference: https://leetcode.com/problems/partition-array-into-two-arrays-to-minimize-sum-difference/
Maybe a significant difference is that the array lengths should be len(nums)/2 🤷

@Locne55
Copy link

Locne55 commented May 3, 2022

thanks for this.

@AntonBelski
Copy link

AntonBelski commented May 4, 2022

Last problem for Pattern: Modified Binary Search similar to this - https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/

@ShreyanGoswami
Copy link

ShreyanGoswami commented Jun 10, 2022

Missing problem for Modified Binary Search is similar to https://leetcode.com/problems/closest-binary-search-tree-value/

@necusjz
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 https://leetcode.com/problems/corporate-flight-bookings/

@ParthPandey2611
Copy link

ParthPandey2611 commented Jun 16, 2022

Thanks for sharing!

@shazib2022skipq
Copy link

shazib2022skipq commented Jul 23, 2022

Thanks a lot.

@dyu222
Copy link

dyu222 commented Jul 30, 2022

^^ here is the first problem is islands https://leetcode.com/problems/number-of-islands/

@shan4993
Copy link

shan4993 commented Aug 1, 2022

Merge Intervals is missing a problem: Conflicting Appointments (medium) -> https://leetcode.com/problems/meeting-rooms/

@shan4993
Copy link

shan4993 commented Aug 3, 2022

Not an exact match but close enough.

Ceiling of a Number (medium) -> https://leetcode.com/problems/search-insert-position/

@khatiba
Copy link

khatiba commented Aug 3, 2022

@i-zanis topological orderings are not unique right?

@swarnabhK
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?

@unrelentingfox
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]

@ayushjainid
Copy link

ayushjainid commented Aug 6, 2022

Not all heroes..

@shan4993
Copy link

shan4993 commented Aug 6, 2022

For Tree BST (right after zig zag) should be https://leetcode.com/problems/average-of-levels-in-binary-tree/

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