human
Program to check if an array is sorted or not ( Iterative and Recursive ) | Function that returns true if array is sorted in non - decreasing order ..
Array has one or no element.
Unsorted pair found.
No unsorted pair found.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to program to check if an array is sorted or not ( Iterative and Recursive ) and the other steps required.
 def arraySortedOrNot ( arr , n ) :
	if ( n == 0 or n == 1 ) :
		return True
	for i in range ( 1 , n ) :
		if ( arr [ i - 1 ] > arr [ i ] ) :
			return False
	return True
arr = [ 20 , 23 , 23 , 45 , 78 , 88 ]
n = len ( arr )
if ( arraySortedOrNot ( arr , n ) ) :
	print ( " Yes " )
else :
	print ( " No " )