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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int maximumOccurrence ( string s ) { int n = s . length ( ) ; map < string , int > freq ; for ( int i = 0 ; i < n ; i ++ ) { string temp = " " ; temp += s [ i ] ; freq [ temp ] ++ ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { string temp = " " ; temp += s [ i ] ; temp += s [ j ] ; freq [ temp ] ++ ; } } int answer = INT_MIN ; for ( auto it : freq ) answer = max ( answer , it . second ) ; return answer ; } int main ( ) { string s = " xxxyy " ; cout << maximumOccurrence ( s ) ; return 0 ; }