Implementation Problems
Implementation problems: read the statement carefully, handle the edge cases, don't lose points on details.
Implementation problems don't require clever algorithms — you need to carefully do exactly what the statement says. Sounds easy, but this is where beginners burn the most attempts.
The three main enemies:
1. Careless reading of the statement: rows and columns swapped, forgetting that numbering starts from one, missing the word "inclusive".
2. Edge cases: n = 1, an empty string, all elements equal, negative numbers.
3. Output format: an extra space, a missing newline, YES instead of Yes.
Example: draw an n by m chessboard out of # characters and dots. The whole problem is spotting the pattern: a cell's color is determined by the parity of the sum of its coordinates.
The chessboard. Enter: 3 5
The second example is subtler: find the SECOND largest element of an array. The naive "sort and take the second-to-last" breaks when the maximum occurs twice, and the two-variable solution needs careful initialization — a classic implementation trap.
The second maximum. Enter: 5, then 3 9 4 9 7
The checklist before submitting any problem:
1. Re-read the statement one more time AFTER writing the code — you'll be surprised how often you've solved "the wrong problem".
2. Run the statement's example by hand.
3. Invent your own edge tests: minimal n, equal elements, extreme values from the constraints.
4. Check the types: does the answer fit in an int?
Four accuracy-training problems are attached to this lesson. Solve them all — and mark the lesson as completed.