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
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
Top Springworks Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Top HR questions asked in Springworks Software Developer Intern
Reviews
Interviews
Salaries
Users/Month