Maximum number of characters between any two same character in a string | Simple C # program to find maximum number of characters between two occurrences of same character ; Driver code
using System ; public class GFG { static int maximumChars ( string str ) { int n = str . Length ; int res = - 1 ; for ( int i = 0 ; i < n - 1 ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( str [ i ] == str [ j ] ) res = Math . Max ( res , Math . Abs ( j - i - 1 ) ) ; return res ; } static public void Main ( ) { string str = " abba " ; Console . WriteLine ( maximumChars ( str ) ) ; } }