Simple C # program to find maximum number of characters between two occurrences of same character
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 ; }