TLE for test case 3000 consecutive 1s
It passes the custom testcase in 24ms, but when I submit it's TLE..\n\nCode:\n\n    public class Solution {\n        public int largestRectangleArea(int[] heigh
It passes the custom testcase in 24ms, but when I submit it's TLE..\n\nCode:\n\n    public class Solution {\n        public int largestRectangleArea(int[] height) {\n            Stack<Integer> maxIdx = new Stack<Integer>();\n            int area = 0;\n            for (int i = 0; i < height.length; i++) {\n                if (maxIdx.isEmpty() || height[maxIdx.peek()] <= height[i]) {\n                    maxIdx.push(i);\n                } else {\n                    int idx = maxIdx.pop();\n                    int width = maxIdx.isEmpty() ? i : i - maxIdx.peek() - 1;\n                    area = Math.max(area, width * height[idx]);\n                    i--;\n                }\n            }\n            while(!maxIdx.isEmpty()) {\n                int idx = maxIdx.pop();\n                int width = maxIdx.isEmpty() ? height.length : height.length - maxIdx.peek() - 1;\n                area = Math.max(area, width * height[idx]);\n            }\n        return area;\n        }\n    }\n\nThanks!
[]