Largest area in histogram

My code has passed all test cases in coding block but not accepted in gfg platform please correct the error.
like this test case

100

133 878 220 361 576 633 78 693 56 932 618 964 129 200 543 271 731 19 887 338 467 956 497 477 886 882 351 481 113 959 493 839 669 581 352 567 128 960 704 276 151 948 499 74 97 841 247 843 944 591 537 117 575 615 806 352 57 61 237 905 490 345 445 891 876 548 511 420 164 957 578 344 461 119 595 356 582 107 467 285 620 611 123 272 884 127 605 138 167 186 302 799 229 230 477 684 666 718 560 884

Expected Output 4674
Myoutput 3380

Hello @arjun1998,

There few logical mistakes in your code.
I have corrected your code:


Refer to comments for better understanding.

Hope, this would help.
Give a like if you are satisfied.

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.