Where should I improve my code?
4 test cases ran, others got "Run error"
By the way, is this the right approach to this problem?
@yobasu2015
The approach is correct. The first problem is you have taken the maximum size of array as 1000, but n is till 10^6.
Another thing is your solution is O(N^2) so it will give TLE here, try to come up with a better solution for finding maximum on left and right.
Tip:- Try doing something in which you first precompute the maximum on left and right for current ‘i’ and then directly use it for every index, like you did here.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.