Getting TLE for this problem

this is the link for my code.
Could you help me optimize my code as I am getting TLE even in the example test case

@sankalp.sharma99
refer to this optimised code