If for any character indegree is not equal to outdegree then ordering is not possible
for i in range ( M ) : NEW_LINE INDENT if ( In [ i ] != out [ i ] ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return isConnected ( g , mark , ord ( arr [ 0 ] [ 0 ] ) - ord ( ' a ' ) ) NEW_LINE