
Let’s think it through · Start with a story
The robot always starts at 0 when looking for the largest value. The girl brings out three cards with negative numbers, and the problem becomes clear right away.
Break down the process
- Ordinary example2, 5, 3
- Boundary exampleOnly one value
- Special dataAll values are negative
- Duplicate valuesThe maximum appears more than once
Boundary tests target inputs that are easy to overlook because of default assumptions.
Choose cases based on the problem’s allowed range, such as the minimum and maximum sizes, equal values, and values exactly at a threshold.
01What is an edge case?
An edge case is an input near the “edges” of a problem’s constraints.
For example, if an array’s length must be between 1 and n, then a length of 1 and the maximum allowed length are important boundaries.
02What are the most common edge cases?
Smallest size
0 or 1 element, if allowed.
Largest size
Close to the problem’s limit.
Extreme values
The smallest or largest integers.
Special patterns
All equal, increasing, or decreasing.
03Why are array indices especially prone to boundary errors?
For an array of length n, the valid indices are:
So i < n and i <= n differ by one character, but that difference determines whether the index goes out of bounds.
04What boundary should you consider with division?
A divisor of 0 is a classic boundary case.
if (b != 0) {
result = a / b;
}
05What edge cases occur in search?
- The start is already the destination.
- No path exists at all.
- There is only one node.
- The graph is disconnected.
06Why test the largest inputs, too?
Because getting the right answer on small inputs does not mean you will avoid:
- Time limit exceeded
- Integer overflow
- Excessive recursion depth
- Memory limit exceeded
07How can you build a habit of checking boundaries?
What you have learned
- Edge cases sit at the boundaries of inputs and rules.
- Minimum and maximum sizes and extreme values are worth testing.
- Array indices, division by zero, and empty data are common risk points.
- Large inputs can reveal complexity and overflow problems.
- Building boundary tests deliberately is an important problem-solving habit.
Next: Why Is My Answer Wrong Even When It Passes the Samples?
Your turn
If the maximum score could be negative, what is the risk of initializing the maximum to 0?
Have an answer? Click to see the explanation
The program might output a 0 that was never in the data. For a nonempty set, you can initialize from its first item.