#include <bits/stdc++.h>

using namespace std;

#include <bits/stdc++.h>

using namespace std;

struct node{

int count[26+1];

};

bool isP(node res,int count[]){

for(int i=0;i<26;++i){

// cout<<count[i]<<" "<<res.count[i]<<endl;

if(count[i]>0&&res.count[i]>0)return 0;

}

// cout<<"atta\n";

return 1;

}

node sol(node a,node b){

node res;

for(int i=0;i<26;++i){

res.count[i]=a.count[i]+b.count[i];

}

return res;

}

void build(node seg[],string &s,int l,int r,int idx){

if(l>r)return ;

if(l==r){

for(int i=0;i<26;++i)seg[idx].count[i]=0;

seg[idx].count[s[l]-'a']+=1;

return ;

}

int mid=(l+r)>>1;

build(seg,s,l,mid,2*idx);

build(seg,s,mid+1,r,1+2*idx);

seg[idx]=sol(seg[2*idx],seg[2*idx+1]);

}

node qu(node seg[],int l,int r,int qs,int qe,int idx){

if(qs>r||qe<l){

node res;

for(int i=0;i<26;++i)res.count[i]=0;

return res;

}

if(qs<=l&&qe>=r)return seg[idx];

int mid=(l+r)>>1;

node la=qu(seg,l,mid,qs,qe,2*idx);

node ra=qu(seg,mid+1,r,qs,qe,2*idx+1);

return sol(la,ra);

}

int main() {

int t;

cin>>t;

while(t--){

string s;

cin>>s;

node seg[4*s.length()+1];

memset(seg,0,sizeof seg);

build(seg,s,0,s.length()-1,1);

int c[26+1];

memset(c,0,sizeof c);

int val=0,i=0;

while(i<s.length()){

c[s[i]-'a']+=1;

val+=1;

node rest=qu(seg,0,s.length()-1,i+1,s.length()-1,1);

if(isP(rest,c)){

cout<<val<<" ";

val=0;

memset(c,0,sizeof c);

}

i+=1;

}

}

return 0;

}

Question No 7 Test cases are weird. Even the Brute Force is giving wrong answer on Test Case 2. Please check once.

***// int is long long int & vi is vector<int> int n; cin>>n; vi v(n); for (int i = 0; i < n; i++) { cin>>v[i]; } int x=0; for(int i=0; i

Hi Raunit, I have reviewed your code for the problem. Please notice the constraints on

`a_i`

in the problem on TJO. The values can also be negative and hence`XOR`

would result in absurd results. In the solution post, I had assumed that`a_i`

values would be non-negative, but I have prepared the problem considering the expected solution only. I have updated the solution post stating this.