Strings formed from given characters without any consecutive repeating characters | Function to print the strings which satisfy the mentioned conditions ; Iterate through all the strings in the array . ; check function to check the conditions for every string ; Function to check whether the string contains any consecutive repetitive characters and any characters other than those in str ; Valid characters check ; Nonrepetitive check ; Driver code
def getStrings ( strr , arr ) : NEW_LINE INDENT for i in range ( len ( arr ) ) : NEW_LINE INDENT if ( check ( arr [ i ] , strr ) ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT def check ( s , strr ) : NEW_LINE INDENT chars = s NEW_LINE for c in chars : NEW_LINE INDENT if c not in strr : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT for i in range ( len ( chars ) - 1 ) : NEW_LINE INDENT if ( chars [ i ] == chars [ i + 1 ] ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT strr = " ABCD " NEW_LINE arr = [ " AABCDA " , " ABCDZADC " , " ABCDBCA " , " ABCDABDCA " ] NEW_LINE getStrings ( strr , arr ) NEW_LINE