Line sweeping & Math O(NlogN) algorithm 🚀
Intuition\n- Let\'s first understand the problem is that we only need to care about the number of overlapped ranges (we can count the total of them by merging t
# Intuition\n- Let\'s first understand the problem is that we only need to care about the number of overlapped ranges (we can count the total of them by merging them) -> For this I used line sweeping by breaking the range into 2 points of event, but you can just use the sorting & merging strategy like the [56. Merge Intervals](https://leetcode.com/problems/merge-intervals/description/) problem.\n- For this type of counting (combinatorics) problem, I first go through the test case, and try to generate a few by myself to pay attention to the result in order to obtain the pattern -> For this problem, the pattern is the power of two: **Pow(2, overlapped_ranges)**!\n\n\n# Complexity\n- Time complexity: O(NlogN)\n\n- Space complexity: O(N)\n\n# Code\n```\nMOD = 10 ** 9 + 7\nclass Solution:\n    def countWays(self, ranges: List[List[int]]) -> int:\n        events = []\n        for s, e in ranges:\n            events.append((s, 0))\n            events.append((e, 1))\n        events.sort()\n        cur = 0\n        overlaps = 0\n        for t, e in events:\n            if e == 0:\n                cur += 1\n                if cur == 1: overlaps += 1\n            else:\n                cur -= 1\n        ans = 2 ** overlaps\n        return ans % MOD\n        \n```
['Math', 'Line Sweep', 'Sorting', 'Python3']