Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
910 B
4
Indexable
Never
        int[][][] maxInSubgrid = new int[N][N][N];
        int[][][] minInSubgrid = new int[N][N][N];
        
        // Populate max and min values for all possible sub-grids
        for (int size = 1; size <= N; size++) {
            for (int i = 0; i <= N - size; i++) {
                for (int j = 0; j <= N - size; j++) {
                    int maxVal = Integer.MIN_VALUE;
                    int minVal = Integer.MAX_VALUE;
                    for (int k = 0; k < size; k++) {
                        for (int l = 0; l < size; l++) {
                            maxVal = Math.max(maxVal, A.get(i + k).get(j + l));
                            minVal = Math.min(minVal, A.get(i + k).get(j + l));
                        }
                    }
                    maxInSubgrid[i][j][size - 1] = maxVal;
                    minInSubgrid[i][j][size - 1] = minVal;
                }
            }
        }
Leave a Comment