Given a rural area is only accessible via railroad. As part of a class on economic development, you've come up with a plan for electrifying these remote settlements. Your plan basically describes n wires connecting some stations along the railroad. ith wire goes between stations l[i] and r[i].
As we all know, wires can't cross because this leads to a short circuit, but they can have the same endpoints. Also, the wires cannot cross the railroad - so in other words, a wire should go either to the left or the right of the railroad.
Is it possible to place the wires in such a way that they don't intersect?
Example
For l = [1, 2, 3] and r = [4, 6, 5], it is possible to arrange the wires such that they do not intesect , so the answer is True
For l = [1, 2, 3] and r = [4, 5, 6], it is not possible to arrange, so the answer is False
For l=[1,3,2,4] and r=[4,5,5,6] the answer is True
What I need is a way to solve the puzzle and how to do it. It seems almost similar to the travelling sales man problem, but I can be wrong too. So how to solve it? How to understand if the arrangements are possible or not?