Sort and count - Java O(N*logN) | O(1)
Intuition\n Describe your first thoughts on how to solve this problem. \nSort and the count the overlap ranges, the result is Permutation with Replacement - 2^n
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSort and the count the overlap ranges, the result is Permutation with Replacement - $$2^n$$.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(N*logN)$$ - from sort\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int countWays(int[][] ranges) {\n        // group all overlap range and count the groups, return 2^count\n        Arrays.sort(ranges, (a, b) -> a[0] - b[0]);\n        int cnt = 0, ans = 1, start = -1, end = -1, mod = 1_000_000_007;\n        for (int[] range : ranges) {\n            if (range[0] > end) {\n                cnt++;\n                start = range[0];\n                end = range[1];\n            } else\n                end = Math.max(end, range[1]);\n        }\n        for (int i = 0; i < cnt; i++) \n            ans = (ans << 1) % mod;\n        return ans;\n    }\n}\n```
['Java']