FastPrepPaint House
Problems/Paint House

Paint House

Shopify logoShopify● MediumINTERNOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names a Paint House-style DP task. The three-color contract, bounds, and examples are practice details; the core task matches at about 65%.

Paint a row of houses using three colors, numbered 0, 1, and 2. The value costs[i][color] is the cost of painting house i that color.

For this exercise, assume each house gets exactly one color and neighboring houses must have different colors. Return the smallest total cost.

Function

minPaintCost(costs: int[][]) → int

Examples

Example 1

costs = [[17,2,17],[16,16,5],[14,3,19]]return = 10

Choose colors [1,2,1]. The cost is 2 + 5 + 3 = 10. Neighboring colors differ, and no valid coloring costs less.

Example 2

costs = [[7,6,2]]return = 2

There is one house, so choose color 2, which costs 2.

Constraints

  • 1 <= costs.length <= 200
  • costs[i].length == 3
  • 0 <= costs[i][color] <= 10000

More Shopify problems

  • Deterministic Secret Santa AssignmentPHONE SCREEN · Seen Oct 2026
  • Mars Rover Robot ControllerPHONE SCREEN · Seen Oct 2026
  • Choose Items for a BackpackOA · Seen May 2026
All Shopify interview questionsSee Shopify hiring insights
Saved
public int minPaintCost(int[][] costs) {
    // Write your code here.
}
Checking account…