How to remove TLE?
How to convert the recursive function in this solution to an iterative function?
Will the iterative function remove TLE?
Please suggest how to optimize this solution to remove TLE.

Pass the vector by reference.
Which means, Replace this function definition,
lld count(lld v,lld w,vector<lld>vt[])
by this,
lld count(lld v,lld w,vector<lld>&vt)

Still getting TLE.

There are too many queries. Answering them in O(N) is not gonna help. You might want to read the editorial for optimal solution.

1 Like