Stop memorizing.
Start reasoning.
Learn the pattern, state the invariant, break it with a counterexample, and verify the result. OpenGrind is DSA practice for an AI era where producing code is cheap and judging it is essential.
Pattern Lab starts before the solution.
Decode the constraints, state the invariant, take one nudge if needed, then reveal the trace and Rust implementation. Your review queue stays on this device.
Open the Pattern Lab →The durable skill is not typing the answer.
You solve one, peek at the answer, close the tab, and forget it by Friday. AI can make that loop even faster without making it deeper. The fix is to recognize the structure, explain why it works, test where it fails, and retrieve it later in a different setting.
Three tracks. One habit.
Each track is a couple of templates up top, then variations that reuse them.
Binary Search
Sorted input and a "find the boundary" question? Three templates cover every variant — exact match, leftmost, and search-on-answer. Learn where the pointers land and stop guessing at `<` vs `<=`.
# template A — closed interval lo, hi = 0, len(nums) - 1 while lo <= hi: mid = (lo + hi) // 2 if nums[mid] == target: return mid elif nums[mid] < target: lo = mid + 1 else: hi = mid - 1
Linked Lists
Pointer choreography without the segfaults. Reverse in place, find the cycle with fast/slow, merge two sorted lists. Once you see the moves, the "hard" ones are just the easy ones stacked.
# reverse in place prev = None while head: nxt = head.next head.next = prev prev = head head = nxt return prev
Sliding Window
Two pointers, one window. Grow it to include, shrink it to stay valid, track the best as you go. Fixed-size or variable — every window problem is the same loop with a different invariant.
# variable window left = 0 for right in range(len(s)): add(s[right]) while invalid(): remove(s[left]) left += 1 best = max(best, right - left + 1)
Patterns, not problems.
The tell that fires before you've read the whole prompt.
See it move.
Watch the search space halve, one probe at a time.
Start anywhere.
A pin for every problem. Grab one and go.
Binary Search
Sorted array, distinct-ish values, "find the index of target" or "does target exist". The most l…
O(log n)Search a 2D Matrix
A matrix where each row is sorted AND the first value of each row exceeds the last of the previo…
O(log(m·n))Koko Eating Bananas
No sorted array in sight — instead: "find the minimum speed / smallest capacity / least X such t…
O(n · log(max pile))Find Minimum in Rotated Sorted Array
A sorted array that has been rotated at an unknown pivot, and you need the minimum (i.e. the rot…
O(log n)Reverse Linked List
A singly linked list, and you need to reverse the direction of all pointers. The signal: "revers…
O(n)Merge Two Sorted Lists
Two sorted linked lists, merge them into one sorted list. The signal: "merge two sorted", "combi…
O(n + m)Linked List Cycle
A linked list that might have a cycle (a node pointing back to an earlier node, creating an infi…
O(n)Merge K Sorted Lists
Given k sorted linked lists, merge them into one sorted list. The signal: "merge k lists", "comb…
O(n log k)Best Time to Buy and Sell Stock
An array of stock prices. You can buy once and sell once (buy must come before sell). Find the m…
O(n)Longest Substring Without Repeating Characters
Find the longest substring with no duplicate characters. Signal: "longest substring", "no repeat…
O(n)Longest Repeating Character Replacement
You can perform at most k character replacements. Find the longest substring with repeating char…
O(n)Permutation In String
Check if a permutation of s1 exists as a substring in s2. Signal: "permutation", "substring", or…
O(n)