Your pattern notes
22 min · Beginner
Need help? Ask a tutor on WhatsApp (opens in a new tab)Solving 100 problems without revision notes feels productive in the moment, yet three weeks later the boundary conditions blur together. A compact set of one-page pattern cards — paired with a spaced revision schedule — turns everything you built in Section 05 into permanent interview muscle memory.
One Page per Pattern
Good revision notes are never full problem transcripts copied from an editor. If your notes are 80 pages long, you will never read them the night before an assessment. Instead, restrict yourself to one single page per pattern (7 pages total for Section 05), divided into five fixed blocks:
- Trigger Clues & Constraints: The exact phrases and n bounds that signal this pattern.
- The Invariant in One Sentence: What must stay true at the end of every loop iteration or recursive call.
- The 10-Line Canonical Template: One battle-tested Java skeleton you can type from memory.
- Top 3 Bugs to Guard Against: The specific traps (like
freq.put(0L, 1)orpath.remove(path.size() - 1)) that break solutions. - Three Anchor Problems (Easy / Medium / Hard): Three representative problems whose titles alone remind you of the whole family.
- Two Pointers anchors: Valid Palindrome (Easy), 3Sum (Medium), Trapping Rain Water (Hard).
- Sliding Window anchors: Max Sum of Size K (Easy), Longest Substring Without Repeating Chars (Medium), Minimum Window Substring (Hard).
- Prefix Sum & Hashing anchors: Pivot Index (Easy), Subarray Sum Equals K / Divisible by K (Medium), Subarrays with K Distinct (Hard).
- Binary Search anchors: First Bad Version (Easy), Search in Rotated Sorted Array (Medium), Split Array Largest Sum (Hard).
Templates and Common Bugs
Almost every wrong submission in a timed round comes from one of six recurring template bugs across the Section 05 patterns. Keep this bug-prevention table at the front of your notebook.
Example 1 · Side-by-Side Canonical Templates: Sliding Window, Prefix Map, and Binary Search
import java.util.HashMap;import java.util.Map;
public class CanonicalTemplatesDemo {
public static int slidingWindowTemplate(int[] nums, int maxSumAllowed) { int left = 0; long sum = 0; int bestLen = 0; for (int right = 0; right < nums.length; right++) { sum += nums[right]; while (sum > maxSumAllowed) { sum -= nums[left++]; } bestLen = Math.max(bestLen, right - left + 1); } return bestLen; }
public static int prefixSumMapTemplate(int[] nums, int target) { Map<Long, Integer> freq = new HashMap<>(); freq.put(0L, 1); long prefix = 0; int count = 0; for (int x : nums) { prefix += x; count += freq.getOrDefault(prefix - target, 0); freq.put(prefix, freq.getOrDefault(prefix, 0) + 1); } return count; }
public static int binarySearchFirstTrueTemplate(int low, int high, int threshold) { while (low < high) { int mid = low + ((high - low) >>> 1); if (mid >= threshold) { high = mid; } else { low = mid + 1; } } return low; }
public static void main(String[] args) { System.out.println("Sliding Window bestLen: " + slidingWindowTemplate(new int[]{2, 1, 3, 2, 4}, 6)); System.out.println("Prefix Sum exact count: " + prefixSumMapTemplate(new int[]{1, -1, 1, -1}, 0)); System.out.println("Binary Search boundary: " + binarySearchFirstTrueTemplate(1, 100, 37)); }}Sliding Window bestLen: 3 Prefix Sum exact count: 4 Binary Search boundary: 37
What this code does
- Memorizing one clean template per pattern eliminates off-by-one hesitation during timed assessments.
- Notice how each template has a single clear invariant:
[left..right]is valid after thewhileloop;freqholds all prefixes beforei;[low..high]brackets the firsttruevalue.
Example 2 · Common Bug Showcase: Reference Aliasing in Backtracking vs Defensive Copy
import java.util.ArrayList;import java.util.List;
public class BacktrackingBugShowcaseDemo { public static void collectBuggy(int[] nums, int idx, List<Integer> path, List<List<Integer>> res) { if (idx == nums.length) { res.add(path); // BUG: adds reference to mutable path! return; } collectBuggy(nums, idx + 1, path, res); path.add(nums[idx]); collectBuggy(nums, idx + 1, path, res); path.remove(path.size() - 1); }
public static void collectFixed(int[] nums, int idx, List<Integer> path, List<List<Integer>> res) { if (idx == nums.length) { res.add(new ArrayList<>(path)); // FIXED: snapshot copy return; } collectFixed(nums, idx + 1, path, res); path.add(nums[idx]); collectFixed(nums, idx + 1, path, res); path.remove(path.size() - 1); }
public static void main(String[] args) { List<List<Integer>> buggy = new ArrayList<>(); collectBuggy(new int[]{1, 2}, 0, new ArrayList<>(), buggy); System.out.println("Buggy subsets: " + buggy);
List<List<Integer>> fixed = new ArrayList<>(); collectFixed(new int[]{1, 2}, 0, new ArrayList<>(), fixed); System.out.println("Fixed subsets: " + fixed); }}Buggy subsets: [[], [], [], []] Fixed subsets: [[], [2], [1], [1, 2]]
What this code does
- In
collectBuggy, all 4 entries inbuggypoint to the exact sameArrayListinstancepath, which is emptied back to[]as the recursion unwinds! - In
collectFixed,new ArrayList<>(path)snapshots the current state ofpathat the leaf.
- Sliding Window bug: Using
ifinstead ofwhilewhen shrinkingleft, or using Sliding Window when negative numbers exist. - Prefix Sum + HashMap bug: Forgetting to seed
map.put(0L, 1)(missing subarrays that start at index0), or forgetting((prefix % k) + k) % kon negative remainders. - Binary Search bug: Infinite loop when
low = midis paired withmid = low + ((high - low) >>> 1)on a 2-element range (always pairhigh = midwithlow = mid + 1). - Backtracking & Bit/Math bugs: Adding
res.add(path)instead ofres.add(new ArrayList<>(path)), forgetting to undo state after recursing, or multiplying twointvalues before casting tolong.
Find the bug
Find the template bug
Each template has one wrong line. Click it.
Longest substring without a repeated letter.
Round 1 of 3A Spaced Revision Plan
Human memory follows Ebbinghaus's forgetting curve: if you solve a hard problem today and never touch it again, you will forget the key trick within 7 to 14 days.
- Day 0 (First Solve): Solve the problem, compare with the model solution, and record any mistake in your Missed Pattern Log.
- Day 1 (24 Hours Later): Without looking at yesterday's code, state the pattern, invariant, and complexity out loud in 60 seconds.
- Day 3 (Cold Re-Code): Re-implement the solution from scratch in a blank editor in under 10 minutes.
- Day 7 (Mixed Weekly Set): Mix 4 logged problems from different modules in random order and solve them without topic labels.
- Day 21 (Pre-Interview Check): Scan your 7 one-page pattern cards and re-solve only the problems that still feel slow.
Example 3 · Spaced Revision Scheduler (1-3-7-21 Day Intervals)
import java.util.Arrays;
public class SpacedRevisionSchedulerDemo { public static int[] reviewDays(int firstSolveDay) { int[] offsets = {1, 3, 7, 21}; int[] schedule = new int[offsets.length]; for (int i = 0; i < offsets.length; i++) { schedule[i] = firstSolveDay + offsets[i]; } return schedule; }
public static void main(String[] args) { System.out.println("Solved on Day 1 -> review on days: " + Arrays.toString(reviewDays(1))); System.out.println("Solved on Day 5 -> review on days: " + Arrays.toString(reviewDays(5))); }}Solved on Day 1 -> review on days: [2, 4, 8, 22] Solved on Day 5 -> review on days: [6, 8, 12, 26]
What this code does
- Each successful recall doubles or triples the interval needed before the next review.
- Notice that on Day 8, a problem from Day 1 (Day +7 review) and a problem from Day 5 (Day +3 review) naturally interleave into a mixed practice session!
Use the 1-3-7-21 Spaced Revision Plan for every problem where you needed a hint or missed the pattern:
Order of execution
Order the revision plan
Put the days of the 1-3-7-21 plan in order.
Next step
Check your understanding
10 quick questions