Ctrl K

Corner Stamps on a Table

Easy
A rows × cols table starts out filled with zeros. Stamps are applied to it one after another: stamp stamps[k] = [a, b] adds one to every cell (x, y) with 0 ≤ x < a and 0 ≤ y < b, that is, to the a × b rectangle anchored at the top-left corner. After all stamps are applied, find the largest number in the table and return how many cells hold it. The table can be huge; there is no need to build it.
Example 1
rows=4, cols=5, stamps=[[3, 4], [2, 5]] → 8

Only the 2 × 4 corner rectangle is covered by both stamps: it holds 2, everything else is smaller. That is 8 cells.

Example 2
rows=2, cols=3, stamps=[] → 6

No stamps were applied, so all 6 cells are zero, and all of them are the maximum.

Constraints
  • 1 ≤ rows, cols ≤ 4 · 10⁴
  • 0 ≤ len(stamps) ≤ 10⁴
  • len(stamps[k]) == 2
  • 1 ≤ a ≤ rows
  • 1 ≤ b ≤ cols
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsAdd One to a Digit Array EasyThe Lost Ticket EasyBest Product of Three EasyThe Biggest Triangle on the Board EasyShadows of Block Towers Easy
loading Python…
Input
rows=4, cols=5, stamps=[[3, 4], [2, 5]]
Expected
8

Run checks the first 3 tests in your browser. Submit checks all 113 tests on the server, hidden ones included.