Testcases passed on CB but not on GFG

I was able to pass all the test-cases here but , when I tried to submit the same code to the same question on GFG (link : https://practice.geeksforgeeks.org/problems/maximum-rectangular-area-in-a-histogram/0 ) , it failed .

To cross check , I even unlocked the editorial ( c++ code ) and copy pasted the code on GFG , but it seems to fail there too. Can you help Identify the error ?

in these cases, the differences arise due to the constraints on input. try with bigger data type and check the corner cases as well, means the end points of input.

thanks

I have indeed been using the large data type and checked the corner cases.
Here is the code I am talking about (Note the function is directly copied from the editorial now but fails to pass all testcases of this question (https://practice.geeksforgeeks.org/problems/maximum-rectangular-area-in-a-histogram/0) ) : https://ideone.com/sUAoFO

problem lies in the line: area = a[x] * (n - x);
the hackerblocks test cases were might weak, thats why its passed.but the code is not correct.

change this line to a[x]*(n-s.top()-1);

thanks

1 Like