• + 0 comments

    for each point, count LEFT and RIGHT length, then evaluate AREA = HEIGHT * (LEFT + RIGHT + 1). important to cast long for c# version

        public static long largestRectangle(List<int> h)
        {
            long max = 0;
            for(int i=0;i<h.Count;i++)
            {
                int n = h[i];
                int l = 0;
                for(int j=i-1;j>=0;j--)
                {
                    int nl = h[j];
                    if (nl < n) break;
                    l++;
                }
                int r = 0;
                for(int j=i+1;j<h.Count;j++)
                {
                    int nr = h[j];
                    if (nr < n) break;
                    r++;
                }
                long a = (long)n*(long)(l+r+1);
                if (a > max) max = a;
            }
            return max;
        }