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 ; Frequency for characters ; Loop to count the occurrence of ith character before jth character in the given String ; Increase the frequency of s [ i ] or c of String ; Maximum occurrence of subsequence of length 1 in given String ; Maximum occurrence of subsequence of length 2 in given String ; Driver Code
using System ; class GFG { static int maximumOccurrence ( string s ) { int n = s . Length ; int [ ] freq = new int [ 26 ] ; int [ , ] dp = new int [ 26 , 26 ] ; for ( int i = 0 ; i < n ; i ++ ) { int x = ( s [ i ] - ' a ' ) ; for ( int j = 0 ; j < 26 ; j ++ ) dp [ x , j ] += freq [ j ] ; freq [ x ] ++ ; } int answer = int . MinValue ; for ( int i = 0 ; i < 26 ; i ++ ) answer = Math . Max ( answer , freq [ i ] ) ; for ( int i = 0 ; i < 26 ; i ++ ) { for ( int j = 0 ; j < 26 ; j ++ ) { answer = Math . Max ( answer , dp [ i , j ] ) ; } } return answer ; } public static void Main ( string [ ] args ) { string s = " xxxyy " ; Console . Write ( maximumOccurrence ( s ) ) ; } }