Maximize the Harvest
Challenge on lesson: Checkpoint — Greedy
CHALLENGE
Difficulty: intermediate+25 XP
**Description:** A orchard has n trees in a row; tree i yields fruit[i].
You pick from a set of trees with one rule: you may not pick from two
**adjacent** trees. Maximize the total harvest. (Classic houses-robber.)
**Input:** Line 1: n (1 ≤ n ≤ 10^5). Line 2: n values (0 ≤ each ≤ 10^9).
**Output:** One integer — the maximum total with no two adjacent picked.
**Example:** 4 / 3 2 5 10 → 13 (trees 3 and 10: indices 0 and 3? No —
3+10 uses indices 0,3: not adjacent → valid → 13; also 2+10 = 12. Max is 13.)
Press Submit to check your solution.
Back to lesson: Checkpoint — Greedy