human
Flip the String by either swapping given characters or rotating it horizontally for Q queries | Function to find final string after applying all Queries on it.
Traverse the Queries array.
Convert A , B to zero indexing.
Query of 1 st type.
Swap ath and bth characters.
Query of 2 nd type.
Swap first N characters with last N characters.
Print answer.
Driver code.
Input.
Function call"
Solution in Python:
 What is a code to flip the String by either swapping given characters or rotating it horizontally for Q queries and the other steps required?
assistant
#Here is code to flip the String by either swapping given characters or rotating it horizontally for Q queries and the other steps required.
 def solve ( S , N , Queries , Q ) :
	S = list ( S )
	for i in range ( Q ) :
		T = Queries [ i ] [ 0 ]
		A = Queries [ i ] [ 1 ]
		B = Queries [ i ] [ 2 ]
		A -= 1
		B -= 1
		if ( T == 1 ) :
			temp = S [ A ]
			S [ A ] = S [ B ]
			S [ B ] = temp
		else :
			for j in range ( N ) :
				temp = S [ j ]
				S [ j ] = S [ j + N ]
				S [ j + N ] = temp
	S = ' ' . join ( S )
	print ( S )
if __name__ == ' _ _ main _ _ ' :
	S = " ABCD "
	N = len ( S ) // 2
	Queries = [ [ 2 , 0 , 0 ] , [ 1 , 1 , 3 ] , [ 2 , 0 , 0 ] ]
	Q = len ( Queries )
	solve ( S , N , Queries , Q )