There are two bus routes red and blue, represented in an array. each index represents a city and each index value represents the cost to reach that index from previous city. You start from city at index 0. There is an additional blue cost applied when you change route from red to blue. Staying on the blue route doesnt incur any blue cost.
Return the minimum cost of reaching each city i.e each index. from city 0.
Example:
Input:
red = [2, 1, 4, 5]
blue = [3, 2, 1, 2]
blueCost = 2
Output: [0, 2, 3, 6, 8]
Explanation: Because we are starting from index 0 to reach it we need 0 cost.
Then we take red route because its minimum so 2, then again red so 2+1 = 3, then
we change route to blue route with blue cost so 3+1+2 = 6, then continue on blue to reach end 6+2 = 8
Can someone help me with intuition or solution. Thanks.