[Java/C++/Python] Sort Solution
Intuition\nSort the input.\n\n\n# Explanation\nlast is the right most end of the current group.\nFor each r in ranges,\nif last < r[0], r[0] starts a new group,
# **Intuition**\nSort the input.\n<br>\n\n# **Explanation**\n`last` is the right most end of the current group.\nFor each `r` in `ranges`,\nif `last < r[0]`, `r[0]` starts a new group,\ncan be either the first or the second group,\nso `res` should be doubled.\nAlso we need to update `last = max(last, r[1])`.\n\nFinally we return resulst `res`.\n<br>\n\n# **Complexity**\nTime `O(sort)`\nSpace `O(sort)`\n<br>\n\n**Java**\n```java\n    public int countWays(int[][] ranges) {\n        int res = 1, last = -1, mod = (int)1e9 + 7;\n        Arrays.sort(ranges, (a, b) -> a[0] - b[0]);\n        for (int[] r: ranges) {   \n            if (last < r[0])\n                res = res * 2 % mod;\n            last = Math.max(last, r[1]);\n        }\n        return res;\n    }\n```\n\n**C++**\n```cpp\n    int countWays(vector<vector<int>>& ranges) {\n        int res = 1, last = -1, mod = 1e9 + 7;\n        sort(ranges.begin(), ranges.end());\n        for (auto r: ranges) {   \n            if (last < r[0])\n                res = res * 2 % mod;\n            last = max(last, r[1]);\n        }\n        return res;\n    }\n```\n\n**Python**\n```py\n    def countWays(self, A: List[List[int]]) -> int:\n        pre = -1\n        res = 0\n        for a,b in sorted(A):\n            res += pre < a\n            pre = max(pre, b)\n        return pow(2, res, 10**9+7)\n```\n
['C', 'Python', 'Java']