human
Can you provide a code to count the number of times graph crosses X and the other steps required given the following:
Count the number of times graph crosses X | Function to to count the number of times the graph crosses the x - axis ..
Iterate over the steps array.
Update the previous level and current level by value given in the steps array.
Condition to check that the graph crosses the origin ..
Driver Code"
Solution in Python:
assistant
#Here is code to count the number of times graph crosses X and the other steps required.
 def times ( steps , n ) :
	current_level = 0
	previous_level = 0
	count = 0
	for i in range ( n ) :
		previous_level = current_level
		current_level = current_level + steps [ i ]
		if ( ( previous_level < 0 and current_level >= 0 ) or ( previous_level > 0 and current_level <= 0 ) ) :
			count += 1
	return count
steps = [ 1 , - 1 , 0 , 0 , 1 , 1 , - 3 , 2 ]
n = len ( steps )
print ( times ( steps , n ) )