human
Check whether an array can be made strictly increasing by modifying atmost one element | Function that returns true if arr [ ] can be made strictly increasing after modifying at most one element.
To store the number of modifications required to make the array strictly increasing.
Check whether the first element needs to be modify or not.
Loop from 2 nd element to the 2 nd last element.
Check whether arr [ i ] needs to be modified.
Modifying arr [ i ].
Check if arr [ i ] is equal to any of arr [ i - 1 ] or arr [ i + 1 ].
Check whether the last element needs to be modify or not.
If more than 1 modification is required.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to check whether an array can be made strictly increasing by modifying atmost one element and the other steps required.
 def check ( arr , n ) :
	modify = 0
	if ( arr [ 0 ] > arr [ 1 ] ) :
		arr [ 0 ] = arr [ 1 ] // 2
		modify += 1
	for i in range ( 1 , n - 1 ) :
		if ( ( arr [ i - 1 ] < arr [ i ] and arr [ i + 1 ] < arr [ i ] ) or ( arr [ i - 1 ] > arr [ i ] and arr [ i + 1 ] > arr [ i ] ) ) :
			arr [ i ] = ( arr [ i - 1 ] + arr [ i + 1 ] ) // 2
			if ( arr [ i ] == arr [ i - 1 ] or arr [ i ] == arr [ i + 1 ] ) :
				return False
			modify += 1
	if ( arr [ n - 1 ] < arr [ n - 2 ] ) :
		modify += 1
	if ( modify > 1 ) :
		return False
	return True
if __name__ == " _ _ main _ _ " :
	arr = [ 2 , 4 , 8 , 6 , 9 , 12 ]
	n = len ( arr )
	if ( check ( arr , n ) ) :
		print ( " Yes " )
	else :
		print ( " No " )