Skip to main content

Practice · 2 of 5

Debug: The Zero Anchor

CHALLENGE
Difficulty: intermediate+25 XP

**Description:** The program must print the maximum VALUE in the array. It fails on some inputs. Find and fix the bug. **Broken code:** ``cpp void solve(std::istream& in, std::ostream& out) { int n; in >> n; long long best = 0; for (int i = 0; i < n; ++i) { long long x; in >> x; best = max(best, x); } out << best; } ` **Input:** Line 1: n (1 <= n <= 100000). Line 2: n integers (|a[i]| <= 10^9). **Output:** One integer — the maximum value. **Example:** 3 / -2 7 -9 -> 7`.

Back to lesson: Practice: Debugging Problem Set