it runs fine in all test cases but
when the size of vector is 2 it gives error…
this questio is from leetcode
here is link:
The program is how to calculate largest rectangle area
The problem is not with vector of size 2, but that you are not iterating in the backward direction.
For example, for cases like {10, 9, 8}, your code will output 10, but the answer should be 8 + 8 + 8 = 24.