Check if both halves of the string have same set of characters | PHP program to check if it is possible to split string or not ; function to check if we can split string or not ; Counter array initialized with 0 ; Length of the string ; traverse till the middle element is reached ; First half ; Second half ; Checking if values are different set flag to 1 ; String to be checked
< ? php $ MAX_CHAR = 26 ; function checkCorrectOrNot ( $ s ) { global $ MAX_CHAR ; $ count1 = array_fill ( 0 , $ MAX_CHAR , NULL ) ; $ count2 = array_fill ( 0 , $ MAX_CHAR , NULL ) ; $ n = strlen ( $ s ) ; if ( $ n == 1 ) return true ; for ( $ i = 0 , $ j = $ n - 1 ; $ i < $ j ; $ i ++ , $ j -- ) { $ count1 [ $ s [ $ i ] - ' a ' ] ++ ; $ count2 [ $ s [ $ j ] - ' a ' ] ++ ; } for ( $ i = 0 ; $ i < $ MAX_CHAR ; $ i ++ ) if ( $ count1 [ $ i ] != $ count2 [ $ i ] ) return false ; return true ; } $ s = " abab " ; if ( checkCorrectOrNot ( $ s ) ) echo " Yes STRNEWLINE " ; else echo " No STRNEWLINE " ; ? >