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

Be the first one to answer
Add answer anonymously...
Springworks Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter