Check if both halves of the string have at least one different character | C # implementation to check if both halves of the string have at least one different character ; Function which break string into two halves Sorts the two halves separately Compares the two halves return true if any index has non - zero value ; Declaration and initialization of counter array ; Driver code
using System ; class GFG { static Boolean function ( char [ ] str ) { int l = str . Length ; Array . Sort ( str , 0 , ( l / 2 ) ) ; Array . Sort ( str , ( l / 2 ) , l - ( l / 2 ) ) ; for ( int i = 0 ; i < l / 2 ; i ++ ) if ( str [ i ] != str [ l / 2 + i ] ) return true ; return false ; } public static void Main ( String [ ] args ) { char [ ] str = ( " abcasdsabcae " ) . ToCharArray ( ) ; if ( function ( str ) ) Console . WriteLine ( " Yes , ▁ both ▁ halves ▁ differ " + " ▁ by ▁ at ▁ least ▁ one ▁ character " ) ; else Console . WriteLine ( " No , ▁ both ▁ halves ▁ do " + " ▁ not ▁ differ ▁ at ▁ all " ) ; } }