For this problem a 2d array of ints represents the value of each…

For this problem a 2d array of ints represents the value of each block in a city. Each element in the array is a city block.
The value of a block could be negative indicating the block is a liability to own. Write a method that finds the value of the most valuable contiguous sub rectangle in the city represented by the 2d array. The sub rectangle must be at least 1 by 1. (If all the values are negative “the most valuable rectangle would be the negative value closest to 0.) Note, for this method you may assume the given 2d array of ints will not cause our method to overflow or underflow the Java int data type.

Consider the followina example. The 2d array of ints has 6 rows and 5 columns per row, representing an area of the city. The cells with the white background and underlined represent the most valuable contiguous sub rectangle in the given array.
Is there a smarter method other than test all the possible rectangles and get the biggest value?
Here is the starter code
/**
* Given a 2D array of ints return the value of the
* most valuable contiguous sub rectangle in the 2D array.
* The sub rectangle must be at least 1 by 1.
*

pre: mat != null, mat.length > 0, mat[0].length > 0,
* mat
is a rectangular matrix.
*

post: return the value of the most valuable contiguous sub rectangle
* in city.
* @param city The 2D array of ints representing the value of
* each block in a portion of a city.
* @return return the value of the most valuable contiguous sub rectangle
* in city.
*/
public static int getValueOfMostValuablePlot(int[][] city) {
// check preconditions
if (city == null || city.length == 0 || city[0].length == 0
|| !isRectangular(city) ) {
throw new IllegalArgumentException(“Violation of precondition: ” +
“getValueOfMostValuablePlot. The parameter may not be null,” +
” must value at least one row and at least” +
” one column, and must be rectangular.”);
}

}
private static boolean isRectangular(int[][] mat) {
// check preconditions
if (mat == null || mat.length == 0) {
throw new IllegalArgumentException(“Violation of precondition: ” +
“isRectangular. Parameter may not be null and must contain” +
” at least one row.”);
}
boolean correct = mat[0] != null;
int row = 0;
while(correct && row < mat.length) { correct = (mat[row] != null) && (mat[row].length == mat[0].length); row++; } return correct; }

Place this order or similar order and get an amazing discount. USE Discount code “GET20” for 20% discount