Link to puzzle
Step 1: Merge all ranges. Step 2. Walk through values and ranges together in a single pass, so a given value only has to compare with the current range.