Check if there exists a permutation of given string which doesn 't contain any monotonous substring | Function to check a string doesn 't contains a monotonous substring ; Loop to iterate over the string and check that it doesn 't contains  the monotonous substring ; Function to check that there exist a arrangement of string such that it doesn 't contains monotonous substring ; Loop to group the characters of the string into two buckets ; Sorting the two buckets ; Condition to check if the concatenation point doesn 't  contains the monotonous string ; Driver Code
function check ( s ) { var ok = true ; for ( var i = 0 ; i + 1 < s . length ; ++ i ) ok &= ( Math . abs ( s [ i ] - s [ i + 1 ] ) != 1 ) ; return ok ; } function monotonousString ( s ) { var odd = " " , even = " " ; for ( var i = 0 ; i < s . length ; ++ i ) { if ( s [ i ] % 2 == 0 ) odd += s [ i ] ; else even += s [ i ] ; } odd = odd . split ( ' ' ) . sort ( ) . join ( ' ' ) ; even = even . split ( ' ' ) . sort ( ) . join ( ' ' ) ; if ( check ( odd + even ) ) return " " ; else if ( check ( even + odd ) ) return " " ; return " " ; } var str = " " ; var ans ; ans = monotonousString ( str ) ; document . write ( ans ) ;