LeetCode's Run Code Feature: A Practical Pre-Submission Validation Strategy
LeetCode's Run Code feature executes your solution against custom input before submission, showing runtime, memory, and output. But hidden tests can impose stricter limits, so use it as a validation tool—not a guarantee.
25 Oct 2025, 15:23 UTC

The Hidden Risk of Blind Submissions
When you're debugging an algorithm on LeetCode, the gap between your local development environment and the platform's judge can be treacherous. You write code, test with sample inputs, hit 'Submit', and watch your acceptance rate plummet—not because your logic is wrong, but because you missed an edge case or misjudged performance constraints.
LeetCode's Run Code feature offers a critical safety net: it executes your code against custom input before you officially submit, showing runtime, memory usage, and output without affecting your submission history. But understanding its limitations is just as important as leveraging its power.
Where Run Code Fits in Your Workflow
The feature lives in the problem's code editor, typically as a text area labeled 'Custom Input' and a 'Run Code' button. When you provide input in the expected format (matching the problem's serialization), LeetCode runs your solution and returns:
- Output: What your function printed or returned
- Console logs: Any stderr output from your code
- Runtime: Execution time in milliseconds
- Memory: Usage in megabytes
This feedback loop is invaluable for validating input parsing, testing boundary conditions, and catching obvious logic errors.
Worked Example: Testing Edge Cases on Two Sum
Consider the classic Two Sum problem where you must find indices of two numbers that add to a target.
Problem constraints: 2 ≤ nums.length ≤ 10⁴, -10⁹ ≤ nums[i] ≤ 10⁹, -10⁹ ≤ target ≤ 10⁹, exactly one solution exists.
Custom input to test:
nums = [0, 4, 3, 0], target = 0
Expected output:
[0, 3]
Why this matters: This tests duplicate zeros—a common oversight. If your hash map solution overwrites the first index, it will fail. Running this through Run Code immediately reveals the bug without risking your acceptance rate.
Verification steps:
- Paste the input into the Custom Input box
- Click Run Code
- Confirm output matches [0, 3]
- Fix any issues before submission
Trade-Offs: Run Code vs. Submission
While Run Code is powerful, it has critical limitations:
- Hidden test cases: The judge runs additional tests you cannot see, including larger inputs and adversarial cases
- Stricter limits: Time and memory constraints may be tighter on the judge than in custom mode
- Input format sensitivity: Malformed input can produce confusing errors that look like algorithm bugs
- Platform variability: Availability and behavior differ between web, mobile, and account tiers
Runtimes from Run Code are not guarantees. A solution that runs in 20ms on a 100-element array might time out on a 10,000-element hidden test.
Actionable Strategy for Pre-Submission Validation
Combine Run Code with a systematic approach:
- Test edge cases first: Empty arrays, single elements, duplicates, zeros, negative numbers
- Scale your inputs: Compare runtime growth between 100, 1,000, and 10,000 elements
- Validate output format: Ensure your return type matches exactly what the judge expects
- Submit only after passing multiple custom tests: This reduces the risk of immediate rejection
Verification remains essential: Always consult LeetCode's current help documentation, as UI placement and feature availability can change. The safest confirmation is running a simple custom case and verifying the output before relying on the feature for complex debugging.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.