• + 0 comments

    JS code :

    function largestRectangle(h) {
        let largest = 0;
        let n = h.length;
        
        
        for(let i = 0; i < n ; i++){
            let counter = 1;
            for(let j = i - 1; j >= 0 ; j--){
                if(j < 0 || h[j] < h[i]){
                  break;
                }
               
                counter++;
            }
            console.log(h[i] + ' : ' + counter);
            let temp = i + 1;
            while(h[temp] >= h[i] && i < n){
                counter++;
                temp++;
            }
            if(h[i] * counter > largest)
            largest = h[i] * counter;
        }
        return largest;
    }