Skip to content

Latest commit

 

History

History
33 lines (25 loc) · 797 Bytes

12.md

File metadata and controls

33 lines (25 loc) · 797 Bytes
int solve(string answerKey, int k,char ch)
{
    int i=0,j=0,ans=0,t=0;

        while(j<answerKey.size())
        {
            if(answerKey[j]==ch)
                t++;
            
            while(i<=j && t>k)
                    {
                        if(answerKey[i]==ch)
                            t--;
                        i++;
                    }
                
        
            ans=max(ans,j-i+1);
            j++;

        }
         //cout<<"i: "<<i<<" j: "<<j<<" Tans: "<<ans<<endl;
        return ans;
}


    int maxConsecutiveAnswers(string answerKey, int k) 
    {
        return max(solve(answerKey,k,'F'),solve(answerKey,k,'T'));
    }