human
Check if a pair of strings exists that starts with and without the character K or not | Function to check whether a pair of strings exists satisfying the conditions.
Stores the visited strings.
Iterate over the array arr [ ].
If first character of current string is K.
Otherwise.
Adding to the visited.
Driver Code.
Given Input"
How can the above be solved in Python?
assistant
#Here is code to check if a pair of strings exists that starts with and without the character K or not and the other steps required.
 def checkhappy ( arr , K , N ) :
	visited = set ( )
	for s in arr :
		if ( s [ 0 ] == K ) :
			if s [ 1 : ] in visited :
				return ' Yes '
		else :
			if ( K + s ) in visited :
				return ' Yes '
		visited . add ( s )
	return " No "
if __name__ == ' _ _ main _ _ ' :
	arr = [ ' a ' , ' ! ▁ a ' , ' b ' , ' ! ▁ c ' , ' d ' , ' ! ▁ d ' ]
	K = ' ! '
	N = len ( arr )
	print ( checkhappy ( arr , K , N ) )