Can somebody tell me why this is getting TLE?

Can somebody help me where i went wrong?
(I know binary search is an option and i will implement that as well)
I was looking at @tmwilliamlin solution for the same question.
Is there a difference in speed between array and vector?

1 Like

Yes there is, array is fixed size thus the compiler can make it much faster.

2 Likes
 for(vector<int>check:v){

You’re creating a copy of each element of each element of v; try:

 for(vector<int>& check:v){

Edit:

Oh, wait - each such vector is tiny (just 3 elements) so it’s probably not that - although you should be doing it anyway :slight_smile:

Edit2:

Hmmm … actually, the speed up is quite significant, so definitely try it, after all :slight_smile:

3 Likes

this actually worked :smiley:
wow thanks a lot @ssjgz
i used to think this only sped up when i am accessing an array during function passing :sweat_smile:
@tmwilliamlin Well yeah my solution passed with almost same time with the method below but will learn this method as well XD

2 Likes

yeah you are correct

1 Like