Unusual TLE on Leetcode

I am not sure if this is the right place to ask for help in a Leetcode problem here ,but I spent much amount of time but could not find the reason for the TLE. Below I am attaching the problem link and my solution link, I will be grateful if someone can tell the reason for TLE.
Problem link
My Solution Link

Thanks for posting it first of all. I solved it during a contest like yours at it got accepted.
But I guess later they have made some modifications over the constraints.

Observe carefully, it’s given in constraint for a circle parameter Ri is MIN(Xi, Yi).
so, You just need to loop i and j for starting from 0 because by the above-mentioned constraints all circles are bound the stay at the first quadrant itself. So we don’t basically need to consider those negative points anyway.

one more optimization that you need is passing circle parameters (i.e v) as reference otherwise it’s showing TLE.

int countLatticePoints(vector<vector<int>>& cir) {
        int cnt=0;
        for(int i=0 ;i<=200;i++) // start from 0
        {
            for(int j=0;j<=200;j++) // start from 0
            {
                for(auto &v : cir) // passing this v as reference otherwise TLE
                {
 
                    if((v[0]-i)*(v[0]-i) + (v[1]-j)*(v[1]-j) <= v[2]*v[2])
                    {
                        cnt++;
                        break;
                    }
                }
            }
        }
        return cnt;
    }

First of all thanks for pointing out the reason, well passing as reference alone solved the problem, but then how do you think passing as reference will optimize the code? Even if the auto loop does not makes a copy of the vector, it still have to traverse the entire vector taking the time complexity to linear.

I didn’t think, I know because I have faced this issue so many times previously :stuck_out_tongue:

Any other tips you wonna share ? that you felt was bit different on Leetcode compilers ! (maybe from your past experience :slight_smile: )

To be honest that reference thing is valid for every platform(spacially gfg, leetcode)! just blindly pass as a reference in every case and also if you are solving in a leetcode contest sometimes brute force can get AC so if you are sure enough that somehow your solution just can pass barely, you can do 2-3 submissions (sometimes maybe 5). And this second CASE is annoying because even sometimes leetcode wants you to write brute force solution but constraints are too tight to pass in single submissions resulting in free penalties that might affect your ranking a lot.