Merge overlapping 2D line segments | Applied Interview Question