Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your intervals are sorted which is great. You can do this in linear time with almost no memory.</p> <p>Start by "flattening" your two sets. That is for set A, start from the lowest interval, and combine any overlapping intervals until you have an interval set that has no overlaps. Then do that for B.</p> <p>Now take your two sets and start with the first two intervals. We'll call these the interval indices for A and B, Ai and Bi.</p> <p>Ai indexes the first interval in A, Bi the first interval in B.</p> <p>While there are intervals to process do the following:</p> <p>Consider the start points of both intervals, are the start points the same? If so advance the start point of both intervals to the end point of the smaller interval, emit nothing to your output. Advance the index of the smaller interval to the next interval. (That is if Ai ends before Bi, then Ai advances to the next interval.) If both intervals end in the same place, advance both Ai and Bi and emit nothing.</p> <p>Is the one start point earlier than the other start point? If so emit the interval from the earlier start point to either a) the start of the later endpoint, or b) the end of the earlier end point. If you chose option b, advance the index of the eariler interval.</p> <p>So for example if the interval at Ai starts first, you emit the interval from start of Ai to start of Bi, or the end of Ai whichever is smaller. If Ai ended before the start of Bi, you advance Ai.</p> <p>Repeat until all intervals are consumed.</p> <p>Ps. I assume you don't have spare memory to flatten the two interval sets into separate buffers. Do this in two functions. A "get next interval" function that advances the interval indices, which does the flattening as necessary, and feed flattened data to the differencing function.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload