I think you can attack this with a fairly typical scan-line approach.
Consider the horizontal scan-line first, sweeping from the top of the figure to the bottom. Observe that the width crossed by the scan-line can only change as it passes across the endpoint of a vertical segment.
So for the horizontal scan-line, you can ignore horizontal segments. Take all of the endpoints of the vertical segments and sort them by their vertical location. (Each endpoint knows whether it is the "top" endpoint or the "bottom" endpoint of its segment).
Process that sorted list in order to simulate the scan line. Maintain an "active set" S, initialized to empty. When you hit a "top" endpoint, add its segment to S. When you hit a "bottom" endpoint, remove its segment from S. Verify that the width of the active set meets your constraint at all times, and you are done.
Use a balanced binary tree (like a C++ std::set
) to represent the active set, using the horizontal position for the comparison function. This allows O(1) retrieval of the leftmost and rightmost segment in the set, so the width calculation is O(1). It also allows O(log n) insertion and removal, and since you insert and remove each vertical segment exactly once, the entire sweep takes O(n log n).
Repeat symmetrically for the vertical scan-line.
Each sort is O(n log n), each scan is O(n log n), times two for each orientation... So the overall algorithm is O(n log n).