Possible Duplicate:
Fastest way to get range complement
I have a sorted array of nonoverlaping ranges for example (0,2],(2,4],(6,9] and I wish to get it’s complement with (0,12] which shoud return (4,6],(9,12] .Whats the fastest way to do that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assume your input data is an array of this form:
Simply add the new elements 0 and 12 to the beginning and end, and you have
And reinterpreting consecutive pairs as intervals, you have:
The fact that you have degenerate intervals makes this something of a mess, but if your original list did not have any degenerate intervals, your output list would not either.
Depending on the format of your data and whether you can do in-place modification, this operation may be
O(1).