Question Description: Moorthy has given a string S of length N to Venkat. If a string contains at least one character whose frequency is greater than or equal to the half of the length of the string, then the string is called superior. ou are required to find the length of the longest superior substring available in the given string S . Note: Here half is considered under integer division i.e. 9/2 = 4, 3/2=1, etc. Constraints: 1 <= T <= 10 1 <= N <= 10^5 The string S contains only lowercase English alphabets. Input Format: First line: Integer T that represents the total number of test cases For each test case:
C Program

#include<stdio.h>
#include<string.h>

int findmax(int* Count){   // mandatory
    int m=0;
    for(int i=0;i<26;i++)
        if(Count[i]>m) m=Count[i];
    return m;
}

int main(){
    int T;
    scanf("%d",&T);

    while(T--){
        int n;
        scanf("%d",&n);

        char s[100005];
        scanf("%s",s);

        int cnt[26]={0};
        int l=0,ans=1;

        for(int r=0;r<n;r++){
            cnt[s[r]-'a']++;

            while(1){
                int len=r-l+1;
                int mx=findmax(cnt);

                if(mx >= len/2) break;

                cnt[s[l]-'a']--;
                l++;
            }

            if(r-l+1 > ans) ans=r-l+1;
        }

        printf("%d\n",ans);
    }
}