Count of strings that does not contain Arc intersection | Function to check if there is arc intersection or not ; Traverse the string S ; Insert all the elements in the stack one by one ; Extract the top element ; Pop out the top element ; Check if the top element is same as the popped element ; Otherwise ; If the stack is empty ; Function to check if there is arc intersection or not for the given array of strings ; Stores count of string not having arc intersection ; Iterate through array ; Length of every string ; Function Call ; Print the desired count ; Driver Code ; Function Call
def arcIntersection ( S , lenn ) : NEW_LINE INDENT stk = [ ] NEW_LINE for i in range ( lenn ) : NEW_LINE INDENT stk . append ( S [ i ] ) NEW_LINE if ( len ( stk ) >= 2 ) : NEW_LINE INDENT temp = stk [ - 1 ] NEW_LINE del stk [ - 1 ] NEW_LINE if ( stk [ - 1 ] == temp ) : NEW_LINE INDENT del stk [ - 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT stk . append ( temp ) NEW_LINE DEDENT DEDENT DEDENT if ( len ( stk ) == 0 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT return 0 NEW_LINE DEDENT def countString ( arr , N ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT lenn = len ( arr [ i ] ) NEW_LINE count += arcIntersection ( arr [ i ] , lenn ) NEW_LINE DEDENT print ( count ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ "0101" , "0011" , "0110" ] NEW_LINE N = len ( arr ) NEW_LINE countString ( arr , N ) NEW_LINE DEDENT