TLE on Code in some cases

This code is giving tle in some cases

hello @Tejas123
image

probably because of so many for loop in ur code.

this is roughly O(n^4).
pls try to think of some efficient logic

its the same algorithm applied in the videos

same 4 loops are also used in code video

then try to submit it on leetcode. ( i cannt help u with python much . as i have very basic knowdege of python)

ok got it the problem was in 4th loop, i changed it to “for k in d[num]”, But how changing this line reduced the time complexity it is also a loop?

again it’s a language specific issue.

what i know array in python is implemnted as list.
so may be thats why it is creating differnce.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.