Protect the Cities

3

4 votes
Data Structures, Easy, Greedy Algorithms, approved
Problem

There are N cities in Imaginary Land. The President of Imaginary Land uses the Cartesian coordinates. Each city is located at some point with integer co-ordinates. The President is very careful and concerned about the well-being of the citizens of his country.

For that reason, he wants to create a boundary and cover all the cities inside that boundary. The boundary should in the shape of a square and should be parallel to the coordinate axes. Find the minimum area enclosed by the boundary such that all the cities are on or inside the boundary.

Input:

The first line of the input contains T, denoting the number of test cases.

Each test case consists of a single positive integer N denoting the number of cities in Imaginary Land.

Each of the next N lines contains two integers xi and yi denoting the coordinates of the ith city.

Output:

For each test-case, output a single non-negative integer denoting the minimum area of the square boundary that encloses all the cities inside or on its boundary.

Constraints:

  • 1T5
  • 1N105
  • 109xi,yi109
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the first test case, all the points are on the boundary of a square of side 2. Hence answer=4.

In the second test case, the smallest square can be drawn is of side 2 having center at (0,0).

Editor Image

?