Minimize length of a string by removing suffixes and prefixes of same characters | Function to find the minimum length of the string after removing the same characters from the end and front of the two strings after dividing into 2 substrings ; Initialize two pointers ; Traverse the string S ; Current char on left pointer ; Shift i towards right ; Shift j towards left ; Return the minimum possible length of string ; Driver Code
function minLength ( s ) { i = 0 ; j = s . length - 1 while ( i < j && s [ i ] == s [ j ] ) { d = s [ i ] while ( i <= j && s [ i ] == d ) i += 1 while ( i <= j && s [ j ] == d ) j -= 1 } return j - i + 1 } S = " " document . write ( minLength ( S ) )