How to Write an ICSC Solution a Grader Can Follow

If you are learning how to write an ICSC solution, start by giving your explanation a job that your code cannot do on its own: tell the grader why your algorithm answers the problem. A Python function might show that you sort a list and compare neighbors. Your written solution should explain why comparing neighbors is enough, even though the problem asks about every possible pair.
A fictional prompt about two close scores
Given a list of 2 to 100,000 integer scores, return the smallest absolute difference between scores at two distinct positions. Scores can repeat. Return the difference itself, not the scores or their positions. For example, [18, 4, 11, 9] has an answer of 2, from the scores 11 and 9. This is a practice prompt, not an ICSC problem.
The phrase distinct positions affects the algorithm. If two entries both have the value 7, they form a valid pair with difference 0. If there is only one entry with that value, you cannot pair it with itself. Sorting keeps every entry, including duplicates. Converting the list to a set would lose information the problem asks you to use.
How to write an ICSC solution from a code-only draft
A first draft might contain nothing but these two lines:
ordered = sorted(scores)
answer = min(b - a for a, b in zip(ordered, ordered[1:]))
The draft gets the right result for the stated inputs, but the grader has to work out what zip pairs together and why those pairs are enough. Adding a comment that says find the minimum difference would name the goal without explaining the choice that makes the algorithm work.
A stronger solution document could describe the approach like this:
I sort the scores in nondecreasing order, keeping duplicate entries. Then I subtract each score from the score immediately after it and return the smallest result. Sorting makes every subtraction nonnegative, so I do not need to take its absolute value.
For the sample, sorting produces [4, 9, 11, 18]. The adjacent differences are 5, 2, and 7, so the algorithm returns 2. This example shows what the scan computes. It does not yet show that the algorithm can safely skip a pair such as 4 and 18, or any other nonadjacent pair on a different input.
Justify the pairs you leave out
A useful proof answers the grader's main objection: the prompt allows any two positions, but the algorithm looks only at neighbors. To close that gap, take any pair of entries in the sorted list. Call the earlier entry x and the later entry y. Because y comes later, the entry immediately after x exists. Call that entry z.
Sorted order gives x ≤ z ≤ y. Therefore z minus x is at most y minus x. The pair x and z uses distinct positions, so it is valid even if their scores are equal. This shows that for every pair, there is an adjacent pair with a difference no larger.
Now apply that statement to a pair with the smallest difference among all valid pairs. An adjacent pair does at least as well, and no adjacent pair can do better than the overall minimum because it is itself a valid pair. So the smallest adjacent difference equals the smallest difference among all pairs. That last sentence connects the proof directly to the value your code returns.
Include code that matches the explanation
Here is a commented Python implementation for the fictional prompt. It uses an explicit loop so the grader can see where the first candidate comes from and which pairs remain to be checked.
def smallest_gap(scores):
# Keep duplicate scores because they occupy distinct positions.
ordered = sorted(scores)
# The prompt guarantees at least two scores, so start with a real pair.
best = ordered[1] - ordered[0]
# The first pair is already checked. Scan each remaining adjacent pair.
for right in range(2, len(ordered)):
gap = ordered[right] - ordered[right - 1]
if gap < best:
best = gap
return best
The initialization matters. Starting best at zero would make the function return zero even for a list such as [4, 9], because no nonnegative gap could replace it. Starting with the first actual gap also handles a two-entry list without a separate branch: the loop has no remaining pairs to check.
With n scores, Python's sort takes O(n log n) time in the worst case under the usual assumption that integer comparisons take constant time. The scan takes O(n) time, so sorting determines the overall worst-case time bound. The implementation uses O(n) extra space, including the new list made by sorted. The scan itself uses only a fixed number of variables.
Check the solution document separately from the code
Read your draft once with the code hidden. Can you tell what the algorithm returns, which candidates it checks, and why it can skip the others? Then read the code with the proof beside it. If your proof relies on keeping duplicates, check that the implementation does so. If you claim to compare all adjacent pairs, check both the pair used for initialization and the first pair visited by the loop.
The ICSC Qualification Round instructions require a written description for every problem and commented source code in the solution document for programming problems. The ICSC 2026 Qualification Round deadline has passed, but you can use the same review method with the training and practice problems: underline the sentence that justifies your main algorithm choice, and revise the draft if all you find is a description of what the code does.
Frequently asked questions
Can I submit code without a written explanation?
No. The Qualification Round requires a written description for every problem. For programming problems, include commented source code in the solution document as well.
Does a worked example count as a proof?
No. An example shows what happens on one input. A proof explains why the method works on every input allowed by the prompt.
What should my code comments explain?
Explain choices that matter, such as why duplicates are kept or why the loop starts at a particular index. Avoid comments that only repeat the code.



