Rectangle Board
Asked at OpenAI
Reported by the problem's creator, not verified
A board is an unbounded grid of integer cells, and RectangleBoard keeps the rectangles placed on it. Each rectangle has a string id, and its coordinates are inclusive: it covers every cell with x1 <= x <= x2 and y1 <= y <= y2.
Examples
Example 1
Input: init =
[], operations =[["add",["a",0,0,2,2]],["add",["b",1,1,3,3]],["add",["c",-2,-2,-2,-2]],["count_at",[1,1]],["count_at",[0,0]],["count_at",[3,3]],["count_at",[3,0]],["count_at",[-2,-2]],["count_at",[-2,-1]],["count_at",[2,2]]]Output:
[null,null,null,2,1,1,0,1,0,2]Explanation: The rectangles a (0,0 to 2,2) and b (1,1 to 3,3) overlap on the cells 1 to 2, so (1,1) and (2,2) are covered twice. (0,0) belongs to a only and (3,3) to b only; the corner cells count because both ends are included. (3,0) is outside both. The single-cell rectangle c covers only (-2,-2).