human
Minimum change in lanes required to cross all barriers | Function to find the minimum number of changes of lane required.
If there is a barrier , then add very large value.
Add the minimum value to move forword with or without crossing barrier.
Return the minimum value of dp [ 0 ] , dp [ 1 ] and dp [ 2 ].
Driver Code"
Solution in Python:
 ... What is a code to minimum change in lanes required to cross all barriers and the other steps required?
assistant
#Here is code to minimum change in lanes required to cross all barriers and the other steps required.
 def minChangeInLane ( barrier , n ) :
	dp = [ 1 , 0 , 1 ]
	for j in range ( n ) :
		val = barrier [ j ]
		if ( val > 0 ) :
			dp [ val - 1 ] = 1000000
		for i in range ( 3 ) :
			if ( val != i + 1 ) :
				dp [ i ] = min ( dp [ i ] , min ( dp [ ( i + 1 ) % 3 ] , dp [ ( i + 2 ) % 3 ] ) + 1 )
	return min ( dp [ 0 ] , min ( dp [ 1 ] , dp [ 2 ] ) )
barrier = [ 0 , 1 , 2 , 3 , 0 ]
N = len ( barrier )
print ( minChangeInLane ( barrier , N ) )