Fails test case 3 and 4

can someone pls check why my code fails test case3 and 4

@Garvit012,sorry for the replying late, i just picked your doubt from the group chat , the problem is that you are using getline to input words but you should use cin for that as a word does’nt have space in them . with getline there is a risk that you might take two or more words together

also , in your print function :-

this step can be reduced (you should have done this if you were passing pre as reference)

pre=pre+n;
print(next,pre); 
int x=pre.length();
pre.erase(x-1,1); 

to this

print(next,pre+n);

corrected code :-

In case of any doubt feel free to ask :slight_smile:

Thanks for your help @O17LPOLA020023 the code is running perfectly now and please check why many of our doubts are being replied very late lately.

@Garvit012, yeah different ta’s are online at different times i will give you my number tell me if no one is replying i will take that doubt

1 Like