Optimize Water Distribution in a Village
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
A village has n houses numbered 1 to n, and every house needs water. There are two ways to supply a house:
- dig a well at house i, which costs wells[i - 1], or
- connect it with a pipe to another house that has water. pipes[j] = [house1, house2, cost] means the two houses can be joined in either direction for cost.
Several pipes may connect the same pair of houses with different costs. Return the minimum total cost to get water to every house.
Examples
Constraints
- 2 <= n <= 10^4
- `wells.length == n`
- 0 <= wells[i] <= 10^5
- 0 <= pipes.length <= 10^4
- 1 <= house1, house2 <= n, house1 != house2
- 0 <= cost <= 10^5
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.