Range intersection is a simple, but non-trivial problem. Its has been answered twice already: Find number range intersection Comparing date ranges The first solutions is O(n) and the second solution is for a database (which is less than O(n) of course). I have the same problem, but for a large n and I am not within a database. This problem