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.
Link:
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