Catch LeetCode Bugs With Custom Input Before You Submit
Use LeetCode's custom-input Run Code as a pre-submission feedback loop to catch edge-case bugs without spending a submission attempt.
06 Mar 2026, 15:33 UTC

The problem: a submission burns on a hidden case
You write a solution, click Submit, and receive Wrong Answer on a test case you never saw. On LeetCode, each submission counts toward your attempt history and can affect acceptance metrics. The frustration is not just the failed case; it is that you spent a submission on a bug you could have caught earlier.
LeetCode offers a Run Code button next to Submit. It executes your code against sample or custom input without creating a submission record. Used as a pre-submission validation step, it turns blind guessing into a short feedback loop.
What Run Code does and does not do
Run Code sends your solution and an input payload to LeetCode's online judge, the service that compiles and executes code in a sandbox. It returns standard output (stdout), the expected output for sample cases, and approximate execution time and memory usage. Because it does not create a submission, repeated runs do not change your submission count or acceptance rate.
The custom-input option lets you type or paste your own test cases, such as an empty array, a single-element array, or an input with duplicate values. This is useful for checking edge cases that the problem's sample tests do not cover.
Run Code is not a substitute for hidden test cases. A solution can pass every custom run and still fail on submission because of an uncovered edge case, a time limit, or a memory limit. Timing and memory shown during a run can also differ from official submission results because of judge load or sandbox warm-up. Exact button placement and labels can change without notice, and the experience may differ between LeetCode's web interface and other clients.
Worked example: validating an edge case
Suppose you are solving a problem that asks whether an array contains any duplicate values. The sample input might be [1,2,3,1], but you are worried about an empty array [] or a single element [5].
- Open the problem in the LeetCode web interface and write your solution in your chosen language.
- Switch the input dropdown from the sample case to Custom input.
- Paste
[]into the custom input box. - Click Run Code.
- Compare the program's stdout against the expected output shown for that input, if provided. If your code throws an error or prints the wrong value, fix the logic before submitting.
Repeat with [5] and a larger array such as [1,2,3,4,5,6,7,8,9,10] to observe behavior across input sizes. If all custom runs produce the expected output, you have more confidence—but not a guarantee—before clicking Submit.
Check that Run Code stayed harmless
Because Run Code should not alter your submission history, you can verify this yourself:
- Open the problem's submission page before running any custom tests and note the number of submissions.
- Run three or four custom inputs with different edge cases.
- Refresh the submission page and confirm the count is unchanged.
- Only then submit your solution for official judging.
If the submission count changes after a Run Code action, treat that as unexpected behavior for your client or interface and avoid relying on Run Code as a free feedback step until it is clarified.
Limitation and practical closing
Custom input is a debugging aid, not a proof of correctness. Hidden test cases may include inputs too large or unusual to paste conveniently, and the online judge's official environment may enforce stricter limits than the Run Code sandbox.
Practical workflow: write the solution, run custom edge cases, inspect stdout, verify submission history is unchanged, then submit. If the official submission returns Wrong Answer or Time Limit Exceeded, use the failure message to add a new custom input and repeat the loop.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.