Max area of histrogram

my ans is correct for custom input but all testcase are wrong.

your approach seems a bit complicated, use this instead

  1. define a stack and push the first element’s index into it
  2. if the current element is less than the element at top, pop until the stack is empty or the current element >= top
  3. while popping calculate maxarea = max(maxarea, (i-top)*arr[top])
  4. push this element
  5. at the end, until the stack is empty use the same formula for maxarea again

@ seemantanishth
I have finded nearest smaller to left and then similarly to right then - them for width and then max area.