Technical Interview Question #9

Technical Interview Series

The distance between two points is …

image 
Create a function which does the following…

Record the last 150 points (x, y) provided to the function (bonus points for allowing a configurable number of points).

Determine which of the previous points are less than a configured distance between the new point and the previous points.

There may be hundreds of new points in a second… Consider the impact of time and CPU impact for your solution.

(if your preferred programming language does not have a square root function, assume one exists.)

Technical Interview Question #8

Technical Interview Series

Create a structure which is used to hold the coordinates of a rectangle within an two dimensional coordinate system.

Now, add the code necessary to support the following:

  1. An arbitrary number of rectangles (think “windows”)
  2. Rectangles that are layered and overlap (and of course various sizes)
  3. Determine the window/rectangle in which a point is contained (factor in layering)

Are there any optimizations?

How would you handle non-rectangular windows efficiently?