Avoid repeated processing of same position.
Editorialist’s solution is commented.
Check for i>0 before accessing its neighbours.
Figured it out last night. Still thank you. Silly mistake!
why every solution which is implemented using recursion giving tle in this question?