public static int maximalInRow(int[] row, int len) {
    	int last = -1;
    	int maxSize = 0;
    	Stack<Integer> stack = new Stack<Integer>();
    	int minHeight = Integer.MAX_VALUE;
    	for(int i=0;i<len;i++) {
    		if(stack.empty() || row[i] >= last) {
    			stack.push(i);
    			last = row[i];
    		}else {
    			last = row[i];
    			minHeight = Integer.MAX_VALUE;
    			int width = 0;
    			while(!stack.empty() && row[stack.peek()] > row[i]) {
    				int position = stack.pop();
    				int height = row[position];
    				
    				width = i - position - 1;
    				maxSize = maxSize(minHeight, width, maxSize);
    				if(height < minHeight) {
    					minHeight = height;
    				}
    			}
    			if(stack.empty()) {
    				width = i;
    				maxSize = maxSize(minHeight, width, maxSize);
    			}else {
    				width = i - stack.peek() - 1;
    				maxSize = maxSize(minHeight, width, maxSize);
    			}
    			stack.push(i);
    			
    		}
    		
    		
    	}
    	
    	while(!stack.empty()) {
			int position = stack.pop();
			int height = row[position];
			int width = len - position - 1;
			maxSize = maxSize(minHeight, width, maxSize);
			if(height < minHeight) {
				minHeight = height;
			}
			width = len - position;
			maxSize = maxSize(minHeight, width, maxSize);
		}
    	int width = len;
		maxSize = maxSize(minHeight, width, maxSize);
		
    	return maxSize;
    	
    	
    	
    	
    	
    	
    }