All guides

Reading a problem statement carefully: common mistakes that cost points

When a submission fails, it is tempting to blame the algorithm. Very often the real cause is simpler: a detail of the problem was misread. These are the mistakes that cost teams the most points, and how to avoid them.

1. Reading the input in the wrong format

Read the Input section line by line. Is the count of numbers given first? Are values on one line or on separate lines? Are there several test cases? A program that reads the input in the wrong order usually prints nonsense or nothing at all.

2. Printing the output in the wrong format

  • Extra text: print only what the Output section asks for. A message like "Answer:" makes the answer wrong.
  • Separators: spaces versus new lines matter when the problem asks for a list.
  • Special cases: many problems ask for a specific value, such as -1, when there is no answer.

3. Ignoring the edge cases

Before you submit, try the smallest and the strangest inputs the constraints allow:

  • N equal to 1, or the smallest value allowed.
  • All values equal, or already sorted, or sorted in reverse.
  • Negative numbers and zero, if the constraints allow them.
  • The largest values, which can cause overflow.

4. Integer overflow

A 32-bit int holds values up to 2,147,483,647. Adding or multiplying large values can go past that limit and silently produce a wrong answer. If the constraints allow values near a billion, use 64-bit integers for sums and products.

5. Misreading what is being asked

Positions or values? Zero-based or one-based? The first answer or any answer? The smallest or the largest? Underline these words in your head before you start. The example and its explanation are there to confirm your understanding, so check that your idea gives the example's output for the right reason.

Use the tools you have

On RelayTrixCode, Run shows exactly where your output differs from the expected output for each example. Custom input lets you try your own edge cases and shows the correct output next to yours, which makes it the quickest way to catch these mistakes before you submit.

Browse the problem library or create a room.