How would you code up a custom rectangle detector?
Anonymous
As the interview was for a software engineer position, the likely problem could be "given the four coordinates, find out if they make a rectangle". I would probe if there any constraints first. If the sides of the rectangle can only be parallel to the axis, then the problem is simple (just test whether Xs, and Ys are the same). It is important to understand whether the coordinates can be given out of order, or, follow a specific pattern (clockwise, top left first, etc.). Knowing that, can also simplify the calculations. Also, depending on the requirements, the same set of coordinates can be considered valid or not valid rectangle. If the rectangle can be tilted on a plane, you need to use some geometry. I wouldn't expect a software engineer to remember the details from the basic geometry, but calculating the length of the segments and/or the angle between them will get you the answer. Ask for special cases, as, can a zero width rectangle be considered a rectangle? Can coordinates be negative, what happens with overflow for signed values, etc.
Check out your Company Bowl for anonymous work chats.