My code while running is showing time limit exceeded. while when i am running it on devc++ it’s showing the correct output
Time limit exceeded
Hey @priyacharaya10 please share your code using ide.codingblocks.com so that i debug it for you. If you don’t know how to share it using ide.codingblocks.com you can ask me that also.
Hey @priyacharaya10 you are getting TLE because you are computing your answer in time complexity of O(N^3) , instead you have to do it in O(N^2) cause of constraints given in question.So try to optimise your code.
where it is mentioned that we have to use a code of O(n^2)?
Every c++ code can perform 10^8 iteration in every second and in this question it’s given that Length of Array should be between 1 and 1000.
Here value of N is 1000, that means your time complexity is O(N^3) which means 10^9 iterations. So you have to lower your complexity down to O(N^2).
Hint:
Instead of using for loop for jth & kth, try using while loop for j & k Variables.
okay thanks a lot. I got you