title: Maximum Area Rectangle In Histogram. Find dimensions of the Max Rectangle
body: <p>I am trying to find maximum area histogram but I would like to track the height and width of the maximum rectangle. I tried different ways by initializing and tracking global width but not able to do it. </p>
  
  <p>This is the code for max area histogram that I have written.
  Used this video to code. <a href="https://www.youtube.com/watch?v=RVIh0snn4Qc&amp;t=888s" rel="nofollow noreferrer">https://www.youtube.com/watch?v=RVIh0snn4Qc&amp;t=888s</a></p>
  
  <pre><code>class Solution:
  def largestRectangleArea(self, hist):
      stack=[]; i=0; area=0
      while i&lt;len(hist):
          if stack==[] or hist[i]&gt;hist[stack[len(stack)-1]]:
              stack.append(i)
          else:
              curr=stack.pop()
              width=i if stack==[] else i-stack[len(stack)-1]-1
              area=max(area,width*hist[curr])
              i-=1
          i+=1
      while stack!=[]:
          curr=stack.pop()
          width=i if stack==[] else len(hist)-stack[len(stack)-1]-1
  
          area=max(area,width*hist[curr])
      return area, 
  
  def maximalRectangle(self, matrix):
      if matrix==[]: return 0
      a=[0 for i in range(len(matrix[0]))]; maxArea=0
      for i in range(len(matrix)):
          for j in range(len(matrix[i])):
              a[j]=a[j]+1 if matrix[i][j]=='1' else 0
  
          maxArea=max(maxArea, self.largestRectangleArea(a)[0])
          print (self.largestRectangleArea(a))
      return maxArea
  
  
  if __name__ == "__main__":
  print( Solution().maximalRectangle([['1', '1', '0', '1', '0', '1'],
                                      ['0', '1', '0', '0', '1', '1'],
                                      ['1', '1', '1', '1', '0', '1'],
                                      ['1', '1', '1', '1', '0', '1']]))
  </code></pre>