Algorithm to compact/simplify ranges? I'm trying to create an algorithm in C# that given a list of ranges (segments) it produces a compacted list of them:

Example 1

Input:
[1, 3], [2, 6]

Output:
[1, 6]

Example 2

Input:
[1, 2], [2, 3]

Output:
[1, 3]

Example 3

Input:
[1, 2], [4, 6], [2,4]

Output:
[1, 6]

Too visualize the problem better, this problem is similar to this: 
if you have a shop that opens from Monday to Tuesday and from Tuesday to Sunday, then you can say that your shop opens from Monday to Sunday. This is what the algorithm should do: to simplify the ranges and give the minimum set of merged ranges.

I'm absolutely lost on how to approach this problem. Thanks in advance.
Make a list of all $2n$ beginning and ending points of the $n$ ranges.  Record each as a (position, type) pair.
Sort this list by position, with starting points comparing below ending points when positions are equal.
Loop through the sorted list, incrementing a counter variable (initially zero) whenever you see a beginning point and decrementing it whenever you see an ending point.  On a 0->1 transition of this variable, output the current position as a starting point.  On a 1->0 transition, output the current position as an ending point.