Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2014/imperative-programming/2/c/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2014 Imperative programming 2 c Solution by
Codex 0 2026-10-31
Every nonempty axis-aligned rectangle has a top-right corner. Enumerate all such corners and retain the greatest area from part (b).The loop invariant is that
var best = 0
var i = 0
while (i < N) {
var j = 0
while (j < N) {
best = math.max(best, maxRectangleAt(i, j))
j += 1
}
i += 1
}best is the greatest area obtained from the corners processed so far, or zero if there are none. ConsequentlyThe preprocessing cost from part (a) is included. An entirely false matrix, or an empty one, returns zero. In the printed example, rows through and columns through give area ; exhaustive corner enumeration confirms that no larger all-true rectangle exists.[ref] New to topics? Read the docs here!
