I have given you the problem details, including it’s sample input and output, constraints etc.
The code that I wrote for this problem is:
However, on submitting, it just passes 8/10 test cases and shows Time Limit Exceeded on other test cases. I firstly wanted to ask that why do I get this TLE and secondly, can you help me optimize the time complexity of this code, such that I don’t give the Time Limit Exceeded message?