Merge collinear overlapping 2D segments | Applied Interview Question