We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
My c++ code using recursion:
T.C -> O(n)
S.C -> O(n)
longlargestRectangle(vector<int>h){longmaxArea;//base caseif(h.empty()){return0;}//second stack to divide the current stack in twovector<int>a;//minimum element present in current stackintminimum=*min_element(h.begin(),h.end());//divide the stackwhile(h.back()!=minimum){a.push_back(h.back());h.pop_back();}// find area using minimum value stack longar=minimum*(a.size()+h.size());//remove the minimum valueh.pop_back();//compare the max area of current stack and that from the divided stack using recursionmaxArea=max(ar,max(largestRectangle(a),largestRectangle(h)));returnmaxArea;}
Largest Rectangle
You are viewing a single comment's thread. Return to all comments →
My c++ code using recursion: T.C -> O(n) S.C -> O(n)