I stopped coding as I realized my order is big. I thought in trying all rectangles (each rectangle start at first row & end at last col), and for each rectangle I do a sliding window in Order (rectangle size). But I believe this is much.
Code: Select all
for (int c1 = 0; c1 < m; ++c1) {
for (int c2 = c1+1; c2 < m; ++c2) {
int windowLastElement = 1000*1000*10;
int startIdx = -1;
// do sliding window
for (int i = 0; i < n; ++i) {
for (int j = c1; j <= c2; ++j) {
}
}
}
}