Count interval intersections | MathWorks Interview Question