Code Room
CodingMediumcod-g1488
Subject Dynamic programming 1dLevel Entry–Mid~15 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

A community garden needs watering over a season. For each day you are given the cost of hiring someone to water (costs vary by day). The plants survive as long as there are never two consecutive days without watering; any single missed day is fine. You choose which days to hire. Return the minimum total cost of a safe schedule. An empty list costs 0. For example, [10, 1, 10, 1, 10] can skip days 0, 2, and 4 and pay only 2.

Implement
min_watering_cost(costs: list[int]) → int
Examples
in[[10,1,10,1,10]]out2
in[[3,4,5]]out4
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.