Back to Q&A board

Challenges with coding interviews: I am not good in covering possible failures

Anonymous Less than 1h ago Software engineer, Meta, Coding, United States

I am able to elaborate the strategy and write the code, but I always fails on corner cases. For example, I write the code but Leetcode and many other online assessment tests fails my code saying there are specific inputs that my code will not work. How I can make this efficiently ? is there a technique for that ?

1 answer
Profile picture for Manny R.
SuperCoach
Software engineer, Product manager, Engineering manager +7 others
Meta, Amazon, Boston Scientific, Google +5 others
4.97 avg rating, 676 clients
Answered less than 1h ago

You do not need to predict every hidden test. You need a repeatable way to find the assumptions your solution depends on and then try to break them.

I use a checklist called BAD SIGNS:

  • B — Boundaries: First and last index, exact thresholds, inclusive versus exclusive ranges.

  • A — Absent or empty: Empty input, missing target, or no valid answer.

  • D — Duplicates: Repeated values, ties, or an input where every value is the same.

  • S — Single or small: One element and the smallest nontrivial case.

  • I — Input extremes: Zero, negatives, large integers, or unusual values allowed by the problem.

  • G — Giant input: Will the solution meet the time, memory, and recursion limits?

  • N — Natural ordering extremes: Sorted, reverse sorted, or all equal inputs.

  • S — Special structure or state: Cycles, disconnected components, overlaps, or source equal to destination.

You do not need a test for every letter on every problem. First clarify what inputs are valid, then choose one small, high-risk example for each relevant category.

The most useful step is to state an invariant: what must remain true every time your loop runs? For a sliding window with no repeated characters, for example, the window must remain duplicate-free and its left boundary must never move backward. Testing "abba" exposes implementations that violate that rule.

Before submitting, do a quick line-of-code attack. For each risky operation, ask: Can this index go out of bounds? Can this map lookup miss? Can this stack be empty? Can this arithmetic overflow? Then dry-run the smallest valid input and one adversarial input, and check worst-case complexity.

That is much more efficient than trying random examples until the solution “looks right.” The goal is to turn corner-case testing into a short, consistent part of how you solve every problem.

I explain the method with worked coding examples in my BAD SIGNS code robustness guide.

Happy coding!

Find a coach
Get support to achieve
your career goals:
practice interviews, improve your resume, negotiate your offers, etc.