Run error in all test cases

sample test case pass but on submitting shows runerroe in all testcases
code link:https://ide.codingblocks.com/s/142767

Hi @Rohan_singla,
When you are pushing the values on to the stack in hist() function, the stack takes value ‘int’ but our answer will exceed the range for int. So that’s why it will give run time error.

hi @sanchit.bansal06
i have made changes still my code show run error
new code link:https://ide.codingblocks.com/s/142767

Hey @Rohan_singla,
Here StacksUsingArrays stack = mainobj.new StacksUsingArrays(1000); you are making a stack of 1000 elements and passing it to hist function to print the answer. Now what if the length of array is greater than 1000, it will run out of space and will give a runtime error because the stack is full.

Also, you need to rewrite your logic, because in case the input is:
5
5 4 3 2 1
The answer should be 9 but your code will give answer 25.

hii @sanchit.bansal06
in case of input
5
5 4 3 2 1
my code is giving 9 not 25
i have checked it
code link:https://ide.codingblocks.com/s/142767

Hey @Rohan_singla,
It is giving me the output as 25 if the input is :
5
5 4 3 2 1

Also, your approach is wrong. You are multiplying arr[i] * l. Then doing l–. Here the input will not be in ascending order. In case the input is:
5
1 2 4 3 5
The output will be 12. But correct answer is 9. Your code will multiply 1* 5, 2* 4, 4* 3, 3* 2, 5* 1. But this is wrong because after 4 we have a bar of size 3, so you cannot multiply it by 3. The correct answer will be 3*3 (taking bars 4,3,5).

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.