human
Check if a decreasing Array can be sorted using Triple cyclic shift | Python3 program for the above approach.
if array is 3 2 1 can ' t ▁ ▁ be ▁ sorted ▁ because ▁ 2 ▁ is ▁ in ▁ ▁ its ▁ correct ▁ position , ▁ 1 ▁ ▁ and ▁ 3 ▁ can ' t shift right because cyclic right shift takes place between 3 elements.
check if its possible to sort.
Number of swap is N / 2 always for this approach.
printing index of the cyclic right shift.
Driver code"
How can the above be solved in Python?
 What is a code to check if a decreasing Array can be sorted using Triple cyclic shift and the other steps required?
assistant
#Here is code to check if a decreasing Array can be sorted using Triple cyclic shift and the other steps required.
 def sortarray ( arr , N ) :
	if ( N == 3 ) :
		print ( " NO " )
	elif ( N % 4 == 0 or N % 4 == 1 ) :
		print ( " YES " )
		print ( N // 2 )
		k = 1
		for l in range ( N // 4 ) :
			print ( k , k + 1 , N )
			print ( k + 1 , N , N - 1 )
			k = k + 2
			N = N - 2
	else :
		print ( " NO " )
if __name__ == " _ _ main _ _ " :
	N = 5
	arr = [ 5 , 4 , 3 , 2 , 1 ]
	sortarray ( arr , N )