The problem is simple, There is some given 1D lines on a plane. We need to find the total size of space having at least one line.
Let me discuss this with an example image-
This may a case. Or
This may be a case or anything like this.
I know it is a basic problem of Sweep Line Algorithm.
But there is no proper document in the internet for it to understand properly.
The one best I have is a blog of Top Coder and that is here.
But it is not clear how to implement it or how may be the simulation.
If I want, we can do it in O(n^2) with 2 loops, but I can't realize how would be the procedure.
Or is there any better algorithm better than that O(n log n)?
Can anyone help me by sharing any Sudo Code or a simulation?
If Sudo code or example code is not available, a simulation for understanding is enough from where I can implement this.
Re- Problem calculating overlapping date ranges is not what I am looking because firstly, it is O(n^2) and so, it is not what I want. And it is not fully described like this question.