Count maximum occurrence of subsequence in string such that indices in subsequence is in A . P . | C # implementation to find the maximum occurrence of the subsequence such that the indices of characters are in arithmetic progression ; Function to find the maximum occurrence of the subsequence such that the indices of characters are in arithmetic progression ; Frequencies of subsequence ; Loop to find the frequencies of subsequence of length 1 ; Loop to find the frequencies subsequence of length 2 ; Finding maximum frequency ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int maximumOccurrence ( string s ) { int n = s . Length ; Dictionary < string , int > freq = new Dictionary < string , int > ( ) ; int i , j ; for ( i = 0 ; i < n ; i ++ ) { string temp = " " ; temp += s [ i ] ; if ( freq . ContainsKey ( temp ) ) { freq [ temp ] ++ ; } else { freq [ temp ] = 1 ; } } for ( i = 0 ; i < n ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { string temp = " " ; temp += s [ i ] ; temp += s [ j ] ; if ( freq . ContainsKey ( temp ) ) freq [ temp ] ++ ; else freq [ temp ] = 1 ; } } int answer = int . MinValue ; foreach ( KeyValuePair < string , int > it in freq ) answer = Math . Max ( answer , it . Value ) ; return answer ; } public static void Main ( string [ ] args ) { string s = " xxxyy " ; Console . Write ( maximumOccurrence ( s ) ) ; } }