I have not used nested loops (i,j) used only one STL and one for loop then why compiler gives TLE…
CODE:CodeChef: Practical coding for everyone
Do you know that max_element
takes linear time?
2 Likes
Hey please use formatted code with good indentation as during debugging indentation makes it faster to debug buggy code.
To answer the question why you are having TLE is that you are using max_element and that takes linear time to find the max element as it needs to traverse the whole length. Now you are using max_element within a loop from i=1 to i=n-1. So it is an overall n^2 algorithm. So it will give TLE as per the constraints specified in the questions!
2 Likes
Thank you so much