solution if of O(n) but still giving tle
please see
Tle for all cases But it sof O(n)
@Vishu_1801 bro its not TLE, its run time error.
I have corrected the code, check for the changes and close the doubt by marking it resolved!
Check the loop and first if condition