Help required for Bon Appetit

I am getting Runtime Error NZEC for my solution to this problem

Could someone tell what is wrong in my solution.
Here’s the link

The code is written in Python 3.6

1 Like

I think u didn’t consider the case for n=0.
So may be list index is going out of range for n=0.

Thanks, that solved the nzec problem. But now it gives TLE. Any idea how to resolve that ?

I think the time limit is too strict.
May be refer to other Python AC submissions to optimize the solution.
As far as your algorithm is concerned I think it is correct and same as other AC submissions.