Given a set of integral coordinates , check whether all the points given lie on side of a possible square such that axis of the square so formed lie parallel to both X-axis and Y-axis .
Suppose points are (0,0) , (1,1) , (2,2) . Answer is not possible .
Suppose points are (0 , 0) , (0,2) , (0,5) , (0,7) , (3,0) Answer is square is possible and minimum length of the side is 7 .
I tried it and came up with many corner cases and it seemed impossible to tackle them individually . I was wondering if anyone can give a more generalised approach towards this kind of problem and how to think in the right direction . Thanks in advance .
Let $\displaystyle x_1 = \min_{(x,y) \in P}{x}$, $\displaystyle x_2 = \max_{(x,y) \in P}{x}$, $\displaystyle y_1 = \min_{(x,y) \in P}{y}$ and $\displaystyle y_2 = \min_{(x,y) \in P}{y}$, where $P$ is the set of points (which I'm assuming to be finite). Consider the (possibly degenerate) rectangle $R$ given by the lines $y = x_1$, $y = x_2$, $x = y_1$ and $x = y_2$.
Now we consider the following two cases:
$x_1 \neq x_2$ and $y_1 \neq y_2$: in this case, for a square to exist, these two conditions must hold: