Check if there exists a permutation of given string which doesn 't contain any monotonous substring | C # implementation such that there are no monotonous string in given string ; 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
using System ; class GFG { static bool check ( string s ) { bool ok = true ; for ( int i = 0 ; i + 1 < s . Length ; ++ i ) ok &= ( Math . Abs ( s [ i ] - s [ i + 1 ] ) != 1 ) ; return ok ; } static string monotonousString ( string s ) { string odd = " " , even = " " ; for ( int i = 0 ; i < s . Length ; ++ i ) { if ( s [ i ] % 2 == 0 ) odd += s [ i ] ; else even += s [ i ] ; } char [ ] oddArray = odd . ToCharArray ( ) ; Array . Sort ( oddArray ) ; odd = new String ( oddArray ) ; char [ ] evenArray = even . ToCharArray ( ) ; Array . Sort ( evenArray ) ; even = new String ( evenArray ) ; if ( check ( odd + even ) ) return " Yes " ; else if ( check ( even + odd ) ) return " Yes " ; return " No " ; } public static void Main ( string [ ] args ) { string str = " abcd " ; string ans ; ans = monotonousString ( str ) ; Console . Write ( ans ) ; } }