Tencent | OA 2019 | Max Area Rectangle
Anonymous User
502

FYI I didn't even have time to do this problem but I will post it as bellow:

You are given a 2D grid and you need to implement following interface:

def insert(x0, y0, x1, y1, color):
	"""
	x0, y0, x1, y1 defines a rectangular area.
	This function would color that area with 'color' and overwrite previous color.
	"""
	pass

def max_area():
	"""
	Return the maximum area of all rectangles of the same color.
	"""
	pass

Example:

insert(0, 0, 2, 2, green)
insert(0, 0, 1, 1, blue)
max_area() --> returns 2 since (1, 0, 2, 2) or (0, 1, 2, 2) are colored green.

Number of colors: unlimited.
Number of calls of insert(): unlimited.
Number of calls of max_area(): only once. After that the program ends.
Size of the grid: unlimited.

Comments (3)