Practice Paint House III
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Paint m houses using colors 1 through n. houses[i] = 0 means unpainted; a positive value is a fixed existing color that cannot be changed. Painting an unpainted house i with color j + 1 costs cost[i][j]. A neighborhood is a maximal consecutive run of one color. Return the minimum added cost that leaves exactly target neighborhoods, or -1 if impossible.
Source: Paint House III on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
houses = [0,0,0,0,0], cost = [[1,10],[10,1],[10,1],[1,10],[5,1]], m = 5, n = 2, target = 3
9
# Example 2
houses = [0,2,1,2,0], cost = [[1,10],[10,1],[10,1],[1,10],[5,1]], m = 5, n = 2, target = 3
11
# Example 3
houses = [3,1,2,3], cost = [[1,1,1],[1,1,1],[1,1,1],[1,1,1]], m = 4, n = 3, target = 3
-1
Constraints
Related LeetCode Problems
Practice more problems similar to Paint House III.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.