EXAMPLE :if i add a range {1,10}
and another range{15,20}
i should get a message saying the ranges from 11 to 14 are missing.
EXAMPLE :if i add a range {1,10} and another range{15,20} i should get a
Share
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.
How are you adding the ranges?
If the ranges are added in order, you can just keep the end of the last range and compare to the start of the range that you add.
If you can add the ranges in any order, you have to do the check when all ranges are added. Sort the ranges on the range start, then loop through the ranges and compare the end of a range with the start of the next range.
update
Example of the second case. First a class to hold ranges:
Create a list of ranges:
Test the ranges:
Note: The code checks for both gaps in the ranges and overlapping ranges. If overlapping ranges is not a problem, just remove the part that checks for
diff > 0.