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
def checkhappy ( arr , K , N ) : NEW_LINE INDENT visited = set ( ) NEW_LINE for s in arr : NEW_LINE INDENT if ( s [ 0 ] == K ) : NEW_LINE INDENT if s [ 1 : ] in visited : NEW_LINE INDENT return ' Yes ' NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if ( K + s ) in visited : NEW_LINE INDENT return ' Yes ' NEW_LINE DEDENT DEDENT visited . add ( s ) NEW_LINE DEDENT return " No " NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ ' a ' , ' ! ▁ a ' , ' b ' , ' ! ▁ c ' , ' d ' , ' ! ▁ d ' ] NEW_LINE K = ' ! ' NEW_LINE N = len ( arr ) NEW_LINE print ( checkhappy ( arr , K , N ) ) NEW_LINE DEDENT