Let's say we have a data structure like this:
var sequences = new List<Tuple<int, int>>
{
new Tuple<int, int>(1, 10),
new Tuple<int, int>(8, 101),
new Tuple<int, int>(102, 103),
new Tuple<int, int>(104, 104),
new Tuple<int, int>(110, 200)
};
I would like to get two results from this collection:
- All missing numbers (in this example: 105, 106, 107, 108, 109)
- All overlapping numbers (in this example: 8, 9, 10)
I could write an algorithm with several loops and helper collections. This course will work, but I wonder if it can be done using LINQ and / or other simpler and shorter algorithms?
Edit: My data structure from the above example consists of 5 sequences, the first of which contains numbers from 1 to 10, the second contains numbers from 8 to 101, etc. .... Since the sequences can be much larger during production (up up to millions), they are not represented with the actual collection (for example, with lists with all numbers), but with the help of Tuples, which represents the minimum and maximum amount of each sequence.
source
share