why i am getting tle.?
my code looks same as editorialist.
Just saw the signature of dfs:
ll dfs(int x,int y,vector<string> v, vector<vector<int>> &vis)
vector<string> &v instead.
it worked. thanks.
but can u explain how is it causing the affect.
I think that’s because multiple different copies of v are getting generated.
When You are sending it like
ie pass by value
its one more copy get created and that copy is used in the function and this copy is destroyed when you return from a function
but When you pass it by refernce means
this way doesn’t create new copy instead it uses this vector from a place where it was created for the first time
And for creation of each copy it takes O(n) time
which is saved in case of pass by reference