Histogram problem

I am facing run error while the 2 cases given in the question work perfectly.
Please look into the code.

Hi @mananaroramail,
Please save the code on ide.codingblocks.com and share the url

The approach you are using will give correct answer for small input and is correct but in the test case the input is a array of 100000 elements . For that your stack is getting overflow and also the height is a long number so if you push your area in the stack then the array exceeds the limit of long number. And also in recursion you are using n^2 time while this problem must be done in linear time O(n). Therefore try to think of a linear approach rather than recursive.

How to control this STACK OVERFLOW ERROR ?
Shall I create a stack which take long input?
And if the answer is going beyond long then how do I compare the areas ??

You will have to use a non recursive approach for that in which less elements are being pushed in the stack as the testcases are tight and if it gives wrong answer then there is a possibility that you are making too many push statements . And other that instead of pushing area just push index and find area from index.

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.