Coding Interview Edge Cases: Checklist and Examples
February 9, 2026(Last edited on: November 15, 2026)By Beyz Editorial Team

Direct answer
Say edge cases before you code. Use one sentence, then name 3–5 tests that actually stress your approach:
“I’ll sanity‑check boundaries, duplicates/ordering, and one worst‑case performance case.”
Pick tests tied to your invariant (what must always be true). Confirm constraints with the interviewer, then implement.
- Boundary example: empty input, single element, off‑by‑one around k.
- Duplicates/ordering example: many repeats, already sorted vs reverse‑sorted.
- Performance example: max input size with adversarial layout.
For a matching complexity line, see Big‑O in interviews: a natural time/space script.
How to say edge cases without sounding scripted
Use a category line, then one or two concrete tests and why they matter:
- “Boundary: empty and single—do we return 0 or 1?”
- “Duplicates: all same value—does the map/window terminate?”
- “Ordering: reverse‑sorted—does my pivot/window rule still move?”
- “Performance: n up to 1e5—two pointers ok, nested loop isn’t.”
Keep it to 15–30 seconds. If the interviewer clarifies, adjust your plan before coding.
The 30 edge cases checklist (with talk tracks)
Use these buckets as prompts; pick only what fits your problem.
1) Boundaries & sizes — “I’ll check smallest and off‑by‑one.”
- Empty input (array/string/list) → “Return 0 or empty result?”
- Single element → “Does base logic handle size 1?”
- Two elements → “Smallest non‑trivial compare/swap.”
- Off‑by‑one around k/index bounds → “Inclusive vs exclusive?”
- Max input size → “Fits memory? Streaming needed?”
2) Numeric range & comparisons — “I’ll confirm value range/signs.”
- Negatives where you assumed non‑negative.
- Zeros (division/multiplication, falsy checks).
- Very large values (overflow or 64‑bit casting).
- Sentinel extremes (INT_MIN/INT_MAX) and comparisons.
- Ties/equal values (stable sort or selection behavior).
3) Duplicates & presence/absence — “I’ll see how repeats behave.”
- All values equal.
- Heavy duplicates clustered together.
- Duplicates at boundaries (first/last positions).
- Missing keys/lookups (map default vs error).
- Presence/absence flags (null/None vs empty container).
4) Ordering & adversarial layouts — “I’ll test friendly vs hostile order.”
- Already sorted input.
- Reverse‑sorted input.
- Nearly sorted with a few outliers.
- Alternating pattern (high‑low‑high‑low).
- Periodic/repeated segments that fake randomness.
5) Pointers, windows, termination — “I’ll ensure progress rules can’t stall.”
- Pointers cross quickly (correct termination).
- Pointers stall on duplicates (need move‑on‑equals rule).
- Window never grows (guard too strict).
- Window never shrinks (blows time/memory).
- “Exactly one” vs “at most/at least” confusion in constraints.
6) Graphs & trees — “I’ll cover shape: disconnected, cycles, skew.”
- Disconnected components (need to visit all nodes).
- Cycles in graphs (must mark visited to avoid loops).
- Self‑loops (node → itself) edge handling.
- Skewed tree (deep recursion/stack depth).
- Missing children/null nodes during traversal.
Mini examples you can reuse in popular patterns
Sliding window: “at most k distinct”
- Talk track: “Window invariant is ≤ k distinct; if > k, shrink from left.”
- Say 3–5: empty input; k = 0 (answer 0); all duplicates with k = 1; k ≥ distinct(nums) (whole array); alternating values that force frequent shrink.
- Complexity line: “Each pointer moves ≤ n → O(n) time, O(k) space.”
Binary search: first occurrence in sorted with duplicates
- Talk track: “Maintain ‘answer can exist on the left’. When nums[mid] ≥ target, move right to mid−1 but record mid if equal.”
- Say 3–5: target absent; single element; all elements = target; target at index 0; monotonic but with long run of duplicates to test leftmost logic.
- Ordering adversary: reverse‑sorted isn’t valid—confirm sorted ascending.
Graph BFS: shortest path in unweighted graph
- Talk track: “BFS by layers; mark visited on enqueue to avoid revisiting.”
- Say 3–5: disconnected nodes (no path); self‑loop; simple cycle; multiple shortest routes (ensure first found by layer breadth); empty graph/start equals goal.
- Termination: ensure queue drains; no re‑enqueue of visited.
DP (top‑down or bottom‑up): coin change minimum coins
- Talk track: “State dp[a] = min coins to make amount a; base dp[0] = 0; transitions from each coin.”
- Say 3–5: amount = 0; impossible amount (return −1); coin value 1 present (greedy not required but dp should work); duplicate coin denominations; large amount to check space and overflow of sentinel values.
For clean narration while you code, this guide pairs well with Explain code in an interview: narration templates.
Practice and verify fast
When you test your own solution during practice:
- Name tests by behavior, not internals, and follow Arrange‑Act‑Assert to keep them readable (Microsoft Learn: unit testing best practices).
- Prefer minimally passing inputs that isolate the behavior you’re checking (keeps tests resilient) (Microsoft Learn).
- Avoid logic in tests (loops/ifs) to keep trust high; use parameterized cases instead (Microsoft Learn).
If you like a structured workflow, see A practical coding interview practice workflow and use AI after you attempt: ask for “break tests that would fail my current implementation,” then re‑implement. A walkthrough is here: LeetCode Assistant: use AI as an interview coach.
If you want lightweight cues during solo drills, Beyz lists interview cheat sheets and a coding assistant you can open alongside practice problems (interview cheat sheets, coding assistant). These capabilities are vendor‑described on the Beyz site (AI Interview Assistant).
A compact talk track you can memorize
- “Plan: I’ll use
with invariant .” - “Edge cases I’ll check before coding: empty/single, duplicates vs ordering, and worst‑case size.”
- “If any of these violate the invariant, I’ll adjust the update/move rule.”
- “Complexity should be
FAQ
When should I mention edge cases?
Right after you state the approach and invariant, before you write code. It’s a 15–30 second checkpoint that often triggers useful clarifications.
How many should I say out loud?
Three to five: one boundary, one duplicates/ordering, one worst‑case performance. Add more only if the interviewer probes.
How do I avoid sounding like I’m reading a list?
Lead with a category line, then name one or two concrete tests tied to your invariant and why they matter. That keeps it conversational and problem‑specific.
Related next reads
- Big‑O in interviews: a natural time/space script
- Explain code in an interview: narration templates
- Practice coding interview follow‑ups the right way
- LeetCode Assistant: use AI as an interview coach
Sources
- AI Screen Solver for Coding Questions | Beyz AI
- AI Interview Assistant | Beyz AI
- Best practices for writing unit tests - .NET | Microsoft Learn