Paint House Problem Statement

You have been given a set of 'N' houses, each house can be painted using one of three colors: green, red, or yellow. A cost matrix is provided with dimensions 'N' * 3, where each element cost[i][j] represents the cost of painting the i-th house (using 0-based indexing) with the j-th color. The color codes are: green - 0, red - 1, and yellow - 2. Your task is to find the minimum total cost to paint all houses such that no two adjacent houses have the same color.

Example:

Input:
T = 1
N = 3
Cost Matrix = [[17, 2, 17], [16, 16, 5], [14, 3, 19]]
Output:
10
Explanation:

The minimum cost is achieved by painting house 0 with color 1 (cost = 2), house 1 with color 2 (cost = 5), and house 2 with color 1 (cost = 3).

Constraints:

  • 1 <= T <= 50
  • 1 <= N <= 10000
  • 0 <= cost[i][j] <= 100

Where cost[i][j] represents the cost of painting the i-th house with j-th color.

Time limit: 1 second

AnswerBot
4mo

Find the minimum total cost to paint all houses such that no two adjacent houses have the same color.

  • Use dynamic programming to keep track of the minimum cost of painting each house with each color wh...read more

Help your peers!
Select
Add answer anonymously...

Springworks Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Linear Probing in Hashing Hashing is a technique to map large non-negative integ...read more
A Software Developer Intern was asked Q. Roman Numeral to Integer Conversion Convert a string representing a Roman numera...read more
A Software Developer Intern was asked Q. Pair Sum Problem Statement You are given an array of integers 'ARR' with a lengt...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Linear Probing in Hashing Hashing is a technique to map large non-negative integ...read more
A Software Developer Intern was asked Q2. Roman Numeral to Integer Conversion Convert a string representing a Roman numera...read more
A Software Developer Intern was asked Q3. Pair Sum Problem Statement You are given an array of integers 'ARR' with a lengt...read more
Springworks Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits