Coding Challenge #16

Coding Challenge Series / Technical Interview Series

You’re given the size of a rectangle, with a width and a height. The X = 0 and Y = 0 point is located in the upper left with the width and height in the lower right. The function you must write takes an array of rectangles (left, top, width, height). Return a list of intersecting rectangle groups. If, for a example, a rectangle is not overlapping, it should be considered a group of one. If two rectangles overlap/intersect, create a rectangle which is inclusive of all points within the two rectangles, and return that as a group, and so on.

A rectangle can be in only one group/set.


  1. So how should you handle the case where you have group 1 and group 2, and the next rectange you check against intersects rectangles in both of those groups?

    Should you end up with a single group which contains group 1, group 2 and next rectangle?

  2. Thanks for the clarifying question.
    You should end up with one group if you had 2 groups formed and the next rectangle overlaps both.

Comments are closed.