Remove characters s [ l ] and s [ i ] .
if ( s . charAt ( l ) == s . charAt ( k ) ) { temp = calc ( l + 1 , k - 1 , s ) * calc ( k + 1 , r , s ) * choose [ ( ( r - l + 1 ) / 2 ) ] [ ( ( r - k ) / 2 ) ] ; ans += temp ; } } return dp [ l ] [ r ] = ans ; } static int waysToClearString ( String S ) {