Check if both halves of the string have at least one different character | C # implementation of the problem ; Function which break string into two halves Increments frequency of characters for first half Decrements frequency of characters for second half true if any index has non - zero value ; Declaration and initialization of counter array ; Driver function
using System ; class GFG { static int MAX = 26 ; static bool function ( String str ) { int l = str . Length ; int [ ] counter = new int [ MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) counter [ i ] = 0 ; for ( int i = 0 ; i < l / 2 ; i ++ ) counter [ str [ i ] - ' a ' ] ++ ; for ( int i = l / 2 ; i < l ; i ++ ) counter [ str [ i ] - ' a ' ] -- ; for ( int i = 0 ; i < MAX ; i ++ ) if ( counter [ i ] != 0 ) return true ; return false ; } public static void Main ( ) { string str = " abcasdsabcae " ; if ( function ( str ) ) Console . Write ( " Yes , ▁ both ▁ halves " + " ▁ differ ▁ by ▁ at ▁ least ▁ one ▁ " + " character " ) ; else Console . Write ( " No , ▁ both ▁ halves " + " ▁ do ▁ not ▁ differ ▁ at ▁ all " ) ; } }