Sorting and merging
Intuition\nThe overlapped ranges can be merged to one continuous range.\nWe get all non-overlapped ranges\nTry to put them to two groups\n\n# Approach\n Describ
# Intuition\nThe overlapped ranges can be merged to one continuous range.\nWe get all non-overlapped ranges\nTry to put them to two groups\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\nO(NLOGN)\n\n- Space complexity:\nO(1)\n\n# Code\n```\npublic class Solution {\n    public int CountWays(int[][] ranges) {\n        Array.Sort(ranges,(a,b)=>{\n            return a[0]-b[0];\n        });\n\n        int n = ranges.Length;\n        int segs= 1;\n        int s = ranges[0][0];\n        int e = ranges[0][1];\n        for(int i=1;i<n;i++)\n        {\n            if(ranges[i][0]<=e)\n            {\n                e = Math.Max(e, ranges[i][1]);\n            }\n            else\n            {\n                segs++;\n                s = ranges[i][0];\n                e = ranges[i][1];\n            }\n        }\n        int result = 1;\n        int M = (int)1e9 + 7;\n        for(int i=0;i<segs;i++)\n        {\n            result *= 2;\n            result %= M;\n        }\n        return result;\n    } \n     \n}\n```
['C#']