fixed threshold
Scan the array once to find its maximum. This value becomes the bar every kid must meet. It never changes — one pass, one number, done.
Picture an award ceremony where every child holding at least as many candies as the
current leader qualifies for a prize. The host finds the top count once, then walks
down the line asking a single question: "If I hand you extra candies, do you reach the
leader?" Each answer is independent — one kid's outcome never changes another's. Find
the maximum, sweep the array, compare each boosted total. O(n) time.
O(n) space for the result.
The algorithm hinges on a single pre-computed threshold. Every evaluation is a self-contained arithmetic check — no kid's result depends on any other kid's.
Scan the array once to find its maximum. This value becomes the bar every kid must meet. It never changes — one pass, one number, done.
Each kid is evaluated as if only they received the extra candies. The question is hypothetical and isolated — kid 0's answer has no bearing on kid 3's.
The comparison is candies[i] + extra ≥ threshold, not strictly greater. A kid who ties the leader after the bonus still qualifies — equality counts.
Two passes over the array — one to establish the bar, one to evaluate every kid against it.
Scan the entire array to compute threshold = candies.Max(). This is the highest candy count any kid currently holds.
Create a boolean array of the same length: result = new bool[candies.Length].
For each index, compute candies[i] + extraCandies and compare against the threshold. Store true if the sum meets or exceeds it, false otherwise.
The boolean array is the answer. No sorting, no second pass needed — each slot was decided in constant time.
The threshold and the extra candy count together determine who qualifies. A few boundary scenarios are worth reasoning through.
When every kid holds the same number of candies, the threshold equals that
value. Adding any positive extra guarantees every kid qualifies — the result
is all true.
With only one child, the threshold is their own count. Adding extra candies
can only increase it — always true. No comparison needed, but
the algorithm handles it naturally.
When the extra amount is too small to close the gap for trailing kids, only the current leader(s) qualify. The further behind a kid is, the more extra candies they'd need.
A kid whose boosted total exactly equals the threshold still qualifies — the
check is ≥, not >. Missing this subtlety
flips answers from true to false.