AlgoMaster Logo

Edge Case Checklist for Coding Interviews

8 min readUpdated December 5, 2026
Listen to this chapter
Unlock Audio

Premium Video

This video is available to premium subscribers only

Unlock Full Access

In this lesson, we'll walk through a practical checklist of edge cases you should test your code against. We'll cover edge cases related to input size, values, and data structures, as well as cases that arise from the answer itself.

We'll also learn how to use this checklist effectively during a coding interview without spending too much time on testing.

What Is an Edge Case?

An edge case is an input that falls at the boundary of what the problem allows or has an unusual structure. An empty array, an array with a single element, or an array where every element is identical are all examples.

Your code might work perfectly on the given examples and still fail on these inputs. This usually happens because your code makes an assumption, such as the array having at least two elements or a valid answer always existing.

firstBigger works on the example [4, 1, 6, 3] but fails on an empty array, a single element and all-same values, because it assumes n ≥ 2 and that an answer exists

Edge cases help expose these hidden assumptions.

Why use a checklist

The challenge is that under interview pressure, it's difficult to remember every case worth checking. That's where a checklist comes in handy. Instead of relying on memory, you go through a small set of categories and identify which ones apply to your problem.

The checklist has five categories:

  1. Input size
  2. Input values
  3. Extreme inputs
  4. Data structures
  5. The answer

You can use this checklist at two points:

  • Before coding, it helps you identify the right questions to ask about the input.
  • After coding, it helps you decide which inputs to test.
The five categories (size, values, extremes, structures, answer) used before coding to ask 'Empty?' and 'Negatives?', and after coding to test inputs like [] and [5]

Let's go through each category.

1. Input Size

Empty input

Start with an empty input. Can the array, string, or list be empty? If so, think about how your code handles it.

For example, if you're finding the maximum of an array and initialize it with the first element, your code will crash when the array is empty.

findMax on an empty array: reading nums[0] throws IndexOutOfBounds

Single element

Next, consider a single element. Many algorithms compare neighboring elements or use two pointers, but with just one element, there's nothing to compare. Make sure your loops don't accidentally skip that element or access an index outside the array.

Two elements

Then, check an input with two elements. It's a great way to see whether your pointers move, meet, and cross correctly.

In binary search, for example, the difference between using left < right and left <= right becomes much easier to spot on small inputs.

Binary search for target 5 in [2, 5] with pointers L and R, comparing while (left < right) and while (left <= right); the empty and one-element inputs sit below

If your loop condition is incorrect, a one-element or two-element array will often expose the bug.

2. Input Values

The second category involves the values in the input.

Negative numbers

Let's start with negative numbers. Consider the problem of finding the maximum sum of a contiguous subarray.

If you initialize the best sum to zero, an array containing -3, -1, and -2 would give you 0. But the correct answer is -1, because the subarray must contain at least one element.

Assuming the input is non-empty, initializing the best sum to the first element avoids this issue.

Zero

Next, consider zero. Zero can cause division-by-zero errors and change the behavior of calculations involving multiplication.

For example, when calculating the product of all elements except the current one:

  • If the array contains exactly one zero, only the position containing that zero will have a nonzero result.
  • If the array contains two or more zeros, every result will be zero.

Your solution must handle both cases correctly.

Duplicates

Next, consider duplicates. If you're looking for two numbers that add up to 6 in an array containing 3 and 3, your solution must treat the two threes as separate elements.

Similarly, if your binary search is supposed to return the first occurrence of a value, testing with duplicates helps verify that it returns the correct index.

Identical elements

Finally, test an input where every element is identical, as this can expose several edge cases at once.

3. Extreme Inputs

There are two types of extreme inputs to consider.

The largest input size

The first is the largest input size allowed by the constraints. Your solution should remain efficient even at this size, so make sure its time complexity fits within the given constraints.

Recursive solutions require special attention here. If each recursive call adds another level to the call stack, a sufficiently large input can cause a stack overflow.

With n = 100,000 the recursion depth is n: calls f(1) to f(5) stack up and f(100,000) goes past the stack limit

Extremely large or small values

The second type involves extremely large or small values, which can cause integer overflow.

In languages like Java and C++, a signed 32-bit integer can hold values up to roughly 2.1 billion (2,147,483,647). If you add together 100,000 numbers, each as large as one billion, the sum can reach 100 trillion, far beyond what a 32-bit integer can store. In such cases, use a 64-bit integer type, such as long in Java or long long in C++.

Another classic example is calculating the middle index in binary search as (left + right) / 2. Even if both indices individually fit within the integer range, adding them together can cause an overflow.

A safer approach is to calculate mid as left plus half the difference between right and left:

This gives us the same result without risking overflow when adding the two indices.

Huge values: 100,000 × 1,000,000,000 overflows a 32-bit int (max 2,147,483,647) but fits in a 64-bit long; with left = 1,500,000,000 and right = 2,000,000,000, left + right overflows to -794,967,296 while (right - left) / 2 is 250,000,000

Python integers support arbitrary precision, so integer overflow isn't a concern when using regular Python integers. However, it's something you need to watch out for in Java, C++, and other languages with fixed-width integer types.

4. Data Structures

The fourth category depends on the data structure you're working with.

Strings

Check an empty string and a string with a single character. Also consider how the problem treats uppercase and lowercase letters, spaces, and punctuation. For example, a palindrome check might require you to ignore everything except letters and digits.

Linked lists

Check an empty list, a single node, and operations that modify the head or tail.

Removing the head often requires special handling because there's no previous node whose pointer you can update. Adding a dummy node before the head allows you to handle this using the same logic as any other node.

Linked list cases: an empty list and a single node; a dummy node D before the head lets prev skip the removed head node, and the function returns D.next

Trees

Check an empty tree, a single node, and a skewed tree, where each non-leaf node has only one child. A completely skewed tree behaves like a linked list, so its height grows linearly with the number of nodes.

Tree cases: a null root, a single node, and a skewed tree 1 → 2 → 3 → 4 whose height 4 equals n

Graphs

Check whether the graph can be disconnected. If you need to visit every node, you'll have to start a search from each unvisited node. Also consider cycles and self-loops, which can cause repeated visits without proper tracking.

A disconnected graph: one component A, B, C with a cycle and another D, E where D has a self-loop; a search starts again at D, and visited marks A to E

Matrices

Check an empty matrix, a single row, a single column, and a non-square matrix.

A disconnected graph: one component A, B, C with a cycle and another D, E where D has a self-loop; a search starts again at D, and visited marks A to E

5. The Answer

The fifth category comes from the answer rather than the input.

  • No valid answer. What if no valid answer exists? Maybe no pair adds up to the target, or there's no path between two nodes. Check what the problem expects you to return in these situations, whether it's -1, an empty list, or false.
  • Multiple valid answers. Clarify whether you can return any valid answer or need to return a specific one, such as the first or the smallest.
  • The whole input is the answer. Consider the case where the answer is the entire input, such as an array where every element already satisfies the required condition.

Using the Checklist in an Interview

During an interview, you won't have time to test every case on this checklist, and you don't need to.

Before coding

Before you start coding, clarify the edge cases that could affect your approach:

  • Can the input be empty?
  • Can it contain negative numbers or duplicates?
  • What should you return if no valid answer exists?

After coding

Once you've finished coding, pick two or three cases that are most likely to break your specific solution and walk through your code with each one:

  • If your solution uses two pointers, try a small input where the pointers meet or cross.
  • If it involves division or multiplication, test with zero.
  • If it updates the answer inside a loop, try an input where the answer appears at the very end.

Handle edge cases through your main logic

Whenever possible, handle edge cases naturally through your main logic rather than adding separate checks for each one. Initializing a maximum with the first element, introducing a dummy node, or choosing the right loop condition can often handle edge cases without adding unnecessary complexity.

If your existing logic already handles a particular edge case, mention it out loud so the interviewer knows you've considered it.

Summary

Most edge cases fall into five categories:

  1. Input size: empty, single-element, and two-element inputs.
  2. Input values: negative numbers, zeros, duplicates, and identical elements.
  3. Extreme inputs: cases that can expose performance issues, stack overflows, or integer overflow.
  4. Data structures: cases specific to your data structure, such as removing the head of a linked list or traversing a disconnected graph.
  5. The answer: no valid answer, multiple valid answers, or an answer at the boundary.