Painting bikes in your shed


Suppose there's a shed full of bikes, and you need to paint them all before selling them. The bikes can all be painted one of 3 colors:

  • green
  • blue
  • red

Each color has a certain cost associated with it. Additionally, no two adjacent bikes can be painted the same color (e.g. you can't use the same color 2x in a row).

We can represent the cost of painting each bike through a matrix that will be of n x 3 shape. For example, cost[0][0] represents the cost of painting the first bike green, cost[2][2] represents the cost of painting the third bike red.

Given this information, write a function that returns the minimum cost of painting the bikes.

For example:

# Input: 
# Output:
# Here we would paint the first bike with the second color, blue, 
# since $2 is the minimum cost, and we would paint the second house
# with the first color, green, since that represents the minimum cost
# and will not be painted the same color as the bike to the left of it


Access restricted

Subscribe to premium account to see the solution.

Get premium now