Answer is coming out to be correct but the test case is not passing, please check
hello @vibhor1007
a) use long long in place of int for area.
b) intiialse area_of_top with 0
c) increase ur hist array say (check max value of n and decide size accordingly)
#include #include<bits/stdc++.h> using namespace std; long long int maximumarea(int hist[], int n){ stack s; long long int maxarea= 0; int tp; long long int area_of_top=0; int i=0; while(i<n){ if(s.empty() || hist[s.top()]<=hist[i]){ s.push(i++); } else{ tp= s.top(); s.pop(); area_of_top = hist[tp]*(s.empty()? i : i- s.top()-1); maxarea = max(maxarea,area_of_top); } } while (s.empty() == false) { tp = s.top(); s.pop(); area_of_top = hist[tp] * (s.empty() ? i : i - s.top() - 1); maxarea= max(maxarea,area_of_top); } return maxarea; } int main() { int n; cin>>n; int hist[1000000]; for(int i=0;i<n;i++){ cin>>hist[i]; } cout<<maximumarea(hist,n)<<endl; return 0; } it is still not working
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.