GSUB _ help

#include
#include
using namespace std;

int main() {
// your code goes here
int t,n,q,a;
int x,y;
cin>>t;
for(int k=0; k<t; k++){
cin>>n>>q;
vector v;
for(int i=0; i<n; i++){
cin>>a;
v.push_back(a);
}
for(int i=0; i<q; i++){
int max_length=1;
int length=1;

        cin>>x>>y;
        v[x-1]=y;
        for(int i=0; i<n-1; i++){
            
            if(v[i]==v[i+1]){
                length=1;
            }else{
                length++;
            }
            if(max_length<length){
                    max_length=length;
            }
        }
        cout<<max_length<<endl;
    }
}
return 0;

}

//what is wrong logic in above code

First of all, you should use fast io, then your check is wrong because you should only update the length only when there is a change of state before and after updating
https://www.codechef.com/viewsolution/39211570

Hope this helps

Edit 1: I dont see ur header properly

Find maximum length of subsequence rather than finding length of subarray

1 Like

yup you confused between sub array and sub sequence .given sub sequence.you did sub array. I too did the same :zipper_mouth_face:

yeah I did both the mistakes mentioned above, thing is they worked for smaller number