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. If such a square is possible give the minimum possible side of the square.
Suppose points are (0,0)
, (1,1)
, (2,2)
.
Answer : square is not possible .
Suppose points are (0,0)
, (0,2)
, (0,5)
, (0,7)
, `(3,0).
Answer : 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 generalized approach towards this kind of problem and how to think in the right direction.
Thanks in advance.
Range of coordinates: -1000 <= x ,y <= 1000
The number of points is <= 50
.
New edit : One more corner case : (2,0) , (0,4) , (1,5) , (5,3) Answer : Square is possible with length 5 . Corner points of the square are (0,0) , (0,5) ,(5,5) ,(5,0)
(1, 0), (0, 1), (2, 1)
. Square with length 2 is possible. (and btw. my answer is the only one that successfully finds that ;) – Nico Schertler(0,0), (0,1), (1,0), (2,0)
) – Dennis Meng