
If your code passes the examples but fails hidden tests, stop guessing individual inputs. Classify the failure, turn the specification and constraints into families of edge cases, reproduce the smallest failing case locally, and compare your program with a simple reference solution. Then keep that case as a regression test. Hidden failures usually come from an untested boundary, a wrong assumption, excessive time or memory use, or an exact input-output mismatch.
Visible examples are illustrations, not a complete specification. They often show ordinary values and a friendly input size. Hidden tests are useful precisely because they can check empty inputs, duplicates, negative values, maximum sizes, unusual ordering, and formatting details without revealing the answers in advance.
A few passing examples show that the program works at a few points in a much larger input space. Massachusetts Institute of Technology testing materials recommend partitioning that space into subdomains, then choosing tests from each partition and its boundaries. For a list problem, useful partitions might include length zero, length one, repeated values, already sorted input, reverse order, negative values, and the largest permitted list.
The key question is not, “What secret test did the grader choose?” It is, “Which valid part of the specification have my local tests not represented?” That shift turns a mysterious red result into a finite search.
Use every clue the platform reveals, even when it hides the input. The category of failure points toward a different investigation.
Carnegie Mellon University debugging notes emphasize identifying the failing input, expected output, and actual output. When the hidden input is unavailable, your job is to manufacture plausible candidates until one reproduces the same failure class.

Suppose the contract says: return the second-largest distinct integer, or no result when fewer than two distinct values exist. A tempting solution sorts the list in descending order and returns the item at index one. It passes [8, 4, 2], but [5, 5, 3] returns 5 instead of 3 because the duplicate occupies index one. An empty list crashes, and an implementation that initializes both tracked values to zero can mishandle an all-negative list such as [-4, -9, -12].
Shrink each failure to its simplest form. The duplicate bug can become [5, 5, 3]; the missing-result rule can be checked with [] and [7]; the negative-value assumption can become [-1, -2]. Small inputs make the incorrect assumption visible. They also become clear permanent tests after the code is fixed.
For small lists, a reference solution can remove duplicates, sort the remaining values, and select the second from the end only when two distinct values remain. Compare this oracle against the faster implementation across many generated short lists. When the answers differ, shrink that list before touching the code. Massachusetts Institute of Technology debugging guidance describes this reduction process as using tests like controlled experiments.
Start from dimensions that can change behavior: input size, value range, repetition, order, structure, and validity. For the second-largest problem, a compact set includes [], [7], [5, 5], [5, 5, 3], [-1, -2], an already sorted list, a reverse-sorted list, and a maximum-length list. Each test has a reason to exist.
Random generation becomes powerful when paired with a property or oracle. Generate short lists containing duplicates and negative values, compute the reference answer, and compare. Random inputs alone can produce noise; an explicit expected result turns them into evidence.

A solution can be logically correct and still fail a large hidden test. If the maximum list length is 200,000, a quadratic method implies roughly 40 billion pair checks in the worst case. A linear scan examines about 200,000 items, while an n log n sort performs on the order of 3.5 million comparison steps. These are scale estimates, not timing promises, but they reveal why friendly examples cannot expose a complexity problem.
Also test the submission wrapper. Read exactly the promised input, handle trailing whitespace, print only the required result, and remove debug messages. If local behavior differs from the judge, check language version, integer range, recursion limits, locale, and whether iteration order is guaranteed.
Passing more hand-picked examples does not prove correctness; it only increases confidence over the cases represented. Testing can reveal bugs, but it cannot generally prove that no bug exists. The specification remains the authority. Do not “fix” a hidden test by adding unexplained special cases, and do not probe a live assessment in ways its academic-integrity rules forbid. Build lawful local tests from the stated contract instead.
If turning a long assignment brief into testable rules is the hard part, Snitchnotes can turn your lecture notes, slides, and PDFs into clearer study notes, quizzes, flashcards, and audio for review.
Classify the failure and restate the contract. A timeout, crash, wrong answer, and formatting error require different investigations, so an immediate rewrite may solve the wrong problem.
A smaller input removes irrelevant details while preserving the bug. That makes the violated assumption easier to see and produces a focused regression test.
Use it on small inputs when its correctness is easier to inspect than the optimized solution. It supplies expected outputs for generated cases; it does not need to meet the full performance limit.
Massachusetts Institute of Technology: Reading 3—Testing
Massachusetts Institute of Technology: Reading 11—Debugging
Carnegie Mellon University: Debugging
Dartmouth College: The Art of Testing (and Writing Good Code)
Notatki, quizy, podcasty, fiszki i czat — z jednego uploadu.
Stwórz pierwszą notatkę za darmo