Your program passes both samples. You submit — Wrong answer on test 7. The samples are written to explain the statement, not to try every corner of it; the hidden tests are written to break programs. This lesson is about breaking yours first: knowing where bugs hide, testing by hand, and letting the computer test for you.
The usual traps
Most wrong answers from correct-looking programs come from a short list. Before you submit, go through it with the problem's limits in front of you:
Test by hand with tiny inputs
For each trap that applies, write a test small enough to solve on paper. Work out the answer before you run the program, and only then compare. Three numbers are usually enough, and a tiny test is easy to read when something goes wrong.
Here is a program that prints the largest of n numbers. It passes every sample with a positive number in it. Try the trap "negative numbers" on it — three negatives:
The fix is to start from a value that really is in the input, int best = a[0];,
or from something smaller than every allowed value.
Now hunt for bugs yourself. Each program below passes its sample; build an input that makes it print a wrong answer: