getting the right answer but on submission it is showing wrong answer.

@everule1 hey can you help me.

Your approach is wrong, no need to check number of tasks are equal or not.
Just run 2 loops:

1. 1st loop for checking truth tasks which are given to shyam are in truth tasks which shyam can perform.
2. 2nf loop for checking dare tasks which are given to shyam are in dare tasks which shyam can perform.

If any one task is not matching from both the loops then print(â€śnoâ€ť)
Else print(â€śyesâ€ť)

Just add break in the if conditions, thats because there may be repeats.

1 Like

Ha ha ofcourse there should be a break statement if the condition fails in the loop with a flag value

Edit : @everule1 sorry I didnâ€™t notice bro.

1 Like

@nagesh_reddy Sorry to say , you are mistaken may be you have not analyse my code completely. Approach was absolutely right. just one mistake was there and that was a break statement, just what @everule1 mentioned. But no worries thanks for your reply.

Sorry for my misunderstanding @ihavejuststart, you are correct I didnâ€™t analyse your code completely. I just saw the increment statement if(Sts[i]==Rtr[j]) r1++; and thought to explain you my approach.
I didnâ€™t realize that your approach is also correct, sorry my mistake.
But in my approach the script is just checking whether the given task is present in the list of shyam can perform, if not it just break the loop and prints no otherwise after all checks it just prints the yes if all tasks are matching.

``````for _ in range(int(input())):
tr = int(input())
trl = set(map(int,input().split()))
dr = int(input())
drl = set(map(int,input().split()))
ts = int(input())
tsl = set(map(int,input().split()))
ds = int(input())
dsl = set(map(int,input().split()))
f = True

for i in dsl:
if i not in drl:
f = False
break
if f:
for i in tsl:
if i not in trl:
f = False
break

if f:
print('yes')
else:
print('no')``````
1 Like

I think they(the setter) intended to store the doable and askable tasks in array like

``````bool doabledare[100]={0};
for(int i=0;i<rs;i++){
int a;
cin>>a;
doabledare[a]=1;
}
``````

something like this

``````#include <iostream>
#include <bits/stdc++.h>
using namespace std;
bool yes(){
int number_of_doable_dares;
bool doabledare[100]={0};
cin>>number_of_doable_dares;
for(int i=0;i<number_of_doable_dares;i++){
int a;
cin>>a;
--a;
doabledare[a]=1;
}
int number_of_doable_truths;
cin>>number_of_doable_truths;
bool doabletruth[100]={0};
for(int i=0;i<number_of_doable_truths;i++){
int a;
cin>>a;
--a;
doabletruth[a]=1;
}
int a;
cin>>a;
--a;
}
int a;
cin>>a;
--a;
}
for(int i=0;i<100;i++){
return 0;
}
return 0;
}
}
return 1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >>t;
while(t--){
if(yes()){
cout<<"yes\n";
}
else{
cout<<"no\n";
}
}
}
``````

This reduces time complexity to O(n)

1 Like

wow setter made the solution very efficient
thank you @everule1 I would have seen the setterâ€™s solution long ago.