Java Easy Solution
\nclass Solution {\n    public int largestRectangleArea(int[] heights) {\n        int ans=0;\n        int ps[]=previousSmall(heights);\n        int ns[]=nextSma
```\nclass Solution {\n    public int largestRectangleArea(int[] heights) {\n        int ans=0;\n        int ps[]=previousSmall(heights);\n        int ns[]=nextSmall(heights);\n        for(int i=0 ;i<heights.length ;i++){\n            ans=Math.max(ans,(ns[i]-ps[i]-1)*heights[i]);\n        }\n        return ans;\n    }\n    public int[] previousSmall(int[] arr) {\n        int n=arr.length;\n        Stack<Integer> s= new Stack<>();\n        int[] ans=new int[n];\n        for(int i=0 ;i<n ;i++){\n            while(!s.isEmpty() && arr[s.peek()]>=arr[i]) s.pop();\n            if(s.isEmpty()) ans[i]=-1;\n            else ans[i]=s.peek();\n            \n            s.push(i);\n        }\n        return ans;\n        \n    }\n    public int[] nextSmall(int[] arr) {\n        int n=arr.length;\n        Stack<Integer> s= new Stack<>();\n        int[] ans=new int[n];\n        for(int i=n-1 ;i>=0 ;i--){\n            while(!s.isEmpty() && arr[s.peek()]>=arr[i]) s.pop();\n            if(s.isEmpty()) ans[i]=n;\n            else ans[i]=s.peek();\n            \n            s.push(i);\n        }\n        return ans;\n        \n    }\n}\n\n```
['Stack', 'Java']