# Chefina and Ranges Video Editorial

Ignore the ambient noise!
Do let me know if you find this useful and you want me to make such videos for the other problems.

13 Likes

I followed your video editorial, but my solution is giving SIGSEGV error for some test cases, could you please tell whatâ€™s wrong ?

``````bool compare(range a, range b){

if(a.l!=b.l){
return a.l<b.l;
}
else{
if(a.val=='a'){
return true;
}
else{
return false;
}
}

}

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
ll l,r;

vector<range> a;

vector<ll> a1;

for(int i=0;i<n;i++){
cin>>l>>r;
a.push_back({l,'a'});
a.push_back({r,'d'});
}

sort(a.begin(),a.end(),compare);

ll cnt = 0;

for(int i=0;i<2*n;i++){
if(a[i].val == 'a'){
cnt++;
}
else{
cnt--;
}
a1.push_back(cnt);
}

ll ans = INT_MAX;

bool flag = false;
for(int i=1;i<((2*n)-1);i++){
if(a[i].val=='a' && flag==true){
ans = min(ans,a1[i]-1);
}
else if(a[i].val=='d'){
flag = true;
}
}

if(ans==INT_MAX){
cout<<-1<<endl;
}

else{
cout<<ans<<endl;
}
}
return 0;
}``````

niceâ€¦broâ€¦i saw SUBSPLAY problemâ€¦u explained clearlyâ€¦and i have subscibed to your channelâ€¦upload more videos as you get free time â€¦if u have time make videos on cookoff alsoâ€¦

1 Like

Very nice videos

2 Likes

Great Work. Keep it Up.

1 Like

XORIT: December Cook-Off

1 Like