The code is giving TLE for some test cases. It is not done in O(n^2). I have tried to do some changes so that it runs faster but still it is giving TLE.
The code given in the code video is also same. Could you help me optimize the code.
P.S : Please check the test cases, there might be some issue.