Output formatting trips up many beginners. The judge compares your output character by character against the expected output. Extra spaces, missing newlines, or wrong capitalization all cause failures.
Read the output specification closely. Does it want items on separate lines or one line? Separated by spaces or commas? With a newline at the end or not?
When in doubt, look at the sample output. It shows exactly what the judge expects. Match it precisely. A working algorithm with wrong formatting still fails.