What you will be able to do#
- Select normal, boundary, tied, adversarial, and maximum-shape cases for the actual contract.
- Separate promised valid input from optional input validation.
- Shrink a failure, repair its cause, and demonstrate a nearby non-regression case.
Choose cases by what they challenge#
State the expected result before tracing the code, and choose only categories that can expose a real branch or assumption.
- Normal: exercises the central path with an independently computed result.
- Empty or singleton: tests initialization, base cases, and termination when the contract permits them.
- Duplicate or tied: tests equality, stable ordering, and deterministic tie policy.
- Boundary: places the answer at the first or last position or exactly on an interval endpoint.
- Adversarial: violates a tempting but unstated assumption, such as signed values in a monotonic window.
- Maximum shape: checks complexity, recursion depth, integer range, and memory assumptions without pretending to execute an enormous input by hand.
Separate preconditions from validation#
If the prompt guarantees a nonempty sorted array, the core algorithm may rely on that promise. If malformed input behavior is part of the contract, validate it explicitly and include those branches in complexity and tests. Do not silently invent rejection behavior or spend the interview defending cases the caller promises cannot occur.
Test the representation's edges#
For indices, test empty boundaries, first and last positions, and half-open ranges. For maps, test duplicates and update order. For graphs, test disconnected nodes, cycles, repeated edges, and whether visited state needs more than node identity. For recursion, test the base case and maximum depth. For mutable structures, verify both the return value and the caller-visible input.
Debug from the first mismatch#
Reduce the failure until every remaining element contributes to it. Write the expected state at each step, locate the first actual state that differs, and connect that divergence to the invariant. Repair the smallest responsible rule, then rerun the failure and one nearby case that already worked.
- Preserve the failing input and expected output.
- Shrink it without removing the failure.
- Trace only the state named by the invariant.
- Repair the cause, not the final symptom.
- Add the failure as a regression and rerun a neighboring valid case.
Worked defect: expire by index#
For fixed-window maximum, the deque stores candidate indices in decreasing value order. Before using its front for a window ending at right, remove any front index smaller than right - windowSize + 1. Comparing only values cannot detect expiration when the same value appears at several positions.
A failing case such as values [9, 1, 1] with window size 2 exposes a stale index if 9 remains after the first window. A nearby non-regression case [1, 9, 1] confirms a still-valid maximum remains until its index leaves the window.
Test integer, text, and mutation assumptions#
Integer totals can exceed an element's range; state the numeric type or safe bound. String indexing may operate on bytes, code units, or Unicode code points, so test a non-ASCII example only when the contract claims that support. For in-place work, retain a copy of the original expectation or assert the exact allowed mutation.
Require evidence before declaring the fix#
A plausible edit is not a completed repair. Show that the previously failing test fails before the change, passes after it, and that at least one neighboring behavior still passes. In a verbal interview, narrate those expected outcomes even when no test runner is available.
Worked example#
Stale maximum after the window moves
A monotonic deque returns 9 for both windows of [9, 1, 1] with width 2 because it never expires the index 0 candidate.
- Capture the failing expectation: window [1, 1] should have maximum 1.
- Trace deque indices and find that index 0 remains when the left boundary becomes 1.
- Expire front indices before reading the maximum for the current window.
- Rerun [9, 1, 1] and [1, 9, 1] to cover expired and retained candidates.
Outcome: The repair follows the index-validity invariant and the regression tests distinguish stale from still-active equal-shaped cases.
Apply the idea#
A fixed-window maximum implementation keeps an expired deque entry. Give a minimal failing test, the invariant violation, the smallest fix, and one nearby non-regression test.
Reveal the worked answer
Use values [9, 1, 1] with width 2: expected maxima are [9, 1], but the stale index can produce [9, 9]. The deque must contain only indices in the current window, with values decreasing from front to back. Before reading the maximum for right, remove front indices less than right - width + 1. Then verify [1, 9, 1] with width 2 still returns [9, 9], because index 1 remains valid in both windows.
Choose the next session#
Before coding, write the expected outputs for one normal, one boundary, and one invariant-breaking case; retain any observed failure as a regression.
Open a practice briefSource and review record#
This original Engineering Foundry guide was checked by Codex against the recorded research scope on 2026-09-05. It has not received independent human editorial review.
Evidence IDs: SRC-DSA-TECH-HANDBOOK-PLAN