Skip to lesson

Patterns checkpoint

You have completed all 12 modules of Section 05: Problem Solving & Coding Patterns! Use this final lesson as a realistic 60-minute timed checkpoint to measure your pattern-recognition speed, accuracy, and readiness for Section 06 (Data Structures & Algorithms).

Timed Checkpoint Test (60-Minute Protocol)

Set a 60-minute timer, close your notes, and treat the MCQ and Practice tabs of this lesson as a real online coding assessment:

  • Part 1 — 10 MCQs (10 minutes): 1 minute per question covering complexity, array/string techniques, two pointers, sliding window, prefix sums, binary search, recursion/backtracking, and bit/math.
  • Part 2 — 2 Easy Problems (12 minutes): Problems 1 and 2 in the Practice tab (6 minutes each).
  • Part 3 — 2 Medium Problems (18 minutes): Problems 3 and 4 in the Practice tab (9 minutes each).
  • Part 4 — 2 Hard Problems (20 minutes): Problems 5 and 6 in the Practice tab (10 minutes each).
  • Rule 1: Do not open the Hint or Solution until the 60-minute timer expires.
  • Rule 2: Write down the pattern name and time/space complexity in a comment before coding each problem.
  • Rule 3: If you get stuck on a problem past its time budget, write a working brute-force or partial solution and move on to the next problem.

Scoring Yourself (100-Point Rubric)

When the 60-minute timer ends, grade your run out of 100 points:

  • MCQ Section (20 points): 2 points for each question answered correctly on the first attempt.
  • Easy Problems 1 & 2 (20 points — 10 pts each): 3 pts for naming the right pattern, 5 pts for passing all test cases without hints, 2 pts for optimal time/space complexity.
  • Medium Problems 3 & 4 (28 points — 14 pts each): 4 pts for pattern selection, 7 pts for passing all test cases without hints, 3 pts for optimal complexity.
  • Hard Problems 5 & 6 (32 points — 16 pts each): 4 pts for pattern selection, 8 pts for passing all test cases (or 4 pts if a working brute-force/partial solution was written), 4 pts for optimal complexity.
  • 85–100 points: Excellent mastery — proceed directly to Section 06 (Data Structures & Algorithms).
  • 70–84 points: Strong foundation — review the specific module(s) where you lost points using the diagnostic map below, then advance to Section 06.
  • Below 70 points: Spend 2–3 days re-solving the practice lessons of your weakest modules without hints before retaking this checkpoint.

Where to Go Back (Diagnostic Map)

Every question and coding problem in this checkpoint maps directly to a module in Section 05 so you never waste time reviewing topics you already know.

  • Missed MCQs 1–2 or Problem 1: Review Modules 5.1–5.4 (Approach, Complexity, Testing, Array & String Techniques: Kadane, Dutch National Flag, In-Place Reversal).
  • Missed MCQs 3–4 or Problem 2: Review Modules 5.5–5.6 (Two Pointers & Sliding Window).
  • Missed MCQs 5–6 or Problem 3: Review Modules 5.7–5.8 (Prefix Sums & Hashing, Binary Search on Sorted Arrays and on Answer).
  • Missed MCQs 7–10 or Problems 4–6: Review Modules 5.9–5.11 (Recursion in Depth, Backtracking & Pruning, Bit Manipulation & Math).

Warm-up problems for the weak spots

Try these three warm-ups before the timed test. Each one revisits a module from the diagnostic map.

Example 1 · Checkpoint Warmup 1: Kadane's Maximum Subarray + Dutch National Flag (Module 5.4)

CheckpointWarmupArrayDemo.javaJava
import java.util.Arrays;
public class CheckpointWarmupArrayDemo {    public static int maxSubArray(int[] nums) {        int cur = nums[0];        int best = nums[0];        for (int i = 1; i < nums.length; i++) {            cur = Math.max(nums[i], cur + nums[i]);            best = Math.max(best, cur);        }        return best;    }
    public static void sortColors(int[] nums) {        int low = 0;        int mid = 0;        int high = nums.length - 1;        while (mid <= high) {            if (nums[mid] == 0) {                int tmp = nums[low]; nums[low++] = nums[mid]; nums[mid++] = tmp;            } else if (nums[mid] == 1) {                mid++;            } else {                int tmp = nums[mid]; nums[mid] = nums[high]; nums[high--] = tmp;            }        }    }
    public static void main(String[] args) {        System.out.println("Max subarray [-2,1,-3,4,-1,2,1,-5,4]: "            + maxSubArray(new int[]{-2, 1, -3, 4, -1, 2, 1, -5, 4}));        int[] colors = {2, 0, 2, 1, 1, 0};        sortColors(colors);        System.out.println("Sorted colors: " + Arrays.toString(colors));    }}
Output
Max subarray [-2,1,-3,4,-1,2,1,-5,4]: 6
Sorted colors: [0, 0, 1, 1, 2, 2]

What this code does

  • Kadane's algorithm decides at each element whether to extend the previous subarray (cur + nums[i]) or start fresh (nums[i]) in O(n) time and O(1) space.
  • Dutch National Flag partitions 0s, 1s, and 2s in a single pass; notice mid does not increment after swapping with high because the incoming element from high has not been inspected yet.

Example 2 · Checkpoint Warmup 2: Sliding Window Anagrams + Prefix XOR Subarrays (Modules 5.6, 5.7, 5.11)

CheckpointWarmupWindowXorDemo.javaJava
import java.util.ArrayList;import java.util.Arrays;import java.util.HashMap;import java.util.List;import java.util.Map;
public class CheckpointWarmupWindowXorDemo {    public static List<Integer> findAnagrams(String s, String p) {        List<Integer> res = new ArrayList<>();        if (s.length() < p.length()) return res;        int[] pFreq = new int[26];        int[] wFreq = new int[26];        for (int i = 0; i < p.length(); i++) {            pFreq[p.charAt(i) - 'a']++;            wFreq[s.charAt(i) - 'a']++;        }        if (Arrays.equals(pFreq, wFreq)) res.add(0);        for (int right = p.length(); right < s.length(); right++) {            wFreq[s.charAt(right) - 'a']++;            wFreq[s.charAt(right - p.length()) - 'a']--;            if (Arrays.equals(pFreq, wFreq)) {                res.add(right - p.length() + 1);            }        }        return res;    }
    public static int countSubarraysWithXor(int[] nums, int targetXor) {        Map<Integer, Integer> freq = new HashMap<>();        freq.put(0, 1);        int prefixXor = 0;        int count = 0;        for (int x : nums) {            prefixXor ^= x;            count += freq.getOrDefault(prefixXor ^ targetXor, 0);            freq.put(prefixXor, freq.getOrDefault(prefixXor, 0) + 1);        }        return count;    }
    public static void main(String[] args) {        System.out.println("Anagrams of \"abc\" in \"cbaebabacd\": " + findAnagrams("cbaebabacd", "abc"));        System.out.println("Subarrays with XOR 6 in [4, 2, 2, 6, 4]: "            + countSubarraysWithXor(new int[]{4, 2, 2, 6, 4}, 6));    }}
Output
Anagrams of "abc" in "cbaebabacd": [0, 6]
Subarrays with XOR 6 in [4, 2, 2, 6, 4]: 4

What this code does

  • findAnagrams uses a fixed-size sliding window of length p.length() and a 26-letter frequency array.
  • countSubarraysWithXor combines Prefix Sums & Hashing with XOR self-inverse: prefixXor[r] ^ prefixXor[l - 1] == targetXor if and only if prefixXor[l - 1] == prefixXor[r] ^ targetXor!

Example 3 · Checkpoint Warmup 3: Binary Search on Answer + Backtracking Subsets With Duplicates (Modules 5.8, 5.10)

CheckpointWarmupSearchBacktrackDemo.javaJava
import java.util.ArrayList;import java.util.Arrays;import java.util.List;
public class CheckpointWarmupSearchBacktrackDemo {    public static List<List<Integer>> subsetsWithDup(int[] nums) {        Arrays.sort(nums);        List<List<Integer>> res = new ArrayList<>();        dfs(nums, 0, new ArrayList<>(), res);        return res;    }
    private static void dfs(int[] nums, int start, List<Integer> path, List<List<Integer>> res) {        res.add(new ArrayList<>(path));        for (int i = start; i < nums.length; i++) {            if (i > start && nums[i] == nums[i - 1]) continue;            path.add(nums[i]);            dfs(nums, i + 1, path, res);            path.remove(path.size() - 1);        }    }
    public static void main(String[] args) {        System.out.println("Subsets of [1, 2, 2]: " + subsetsWithDup(new int[]{1, 2, 2}));    }}
Output
Subsets of [1, 2, 2]: [[], [1], [1, 2], [1, 2, 2], [2], [2, 2]]

What this code does

  • Sorting nums groups duplicates side-by-side so if (i > start && nums[i] == nums[i - 1]) continue; skips duplicate branches at the same recursion tree level.
  • When recursing to i + 1, the next level has start = i + 1, which still allows picking the second 2 to form [1, 2, 2] and [2, 2].

Next step

Check your understanding

10 quick questions