Using concept of merging intervals
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(nlogn)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n# Code\n```\nclass Solution {\npublic:\n    int mod=(int)(1e9+7);\n    int countWays(vector<vector<int>>& it) {\n        int cnt=1; \n        int n = it.size();\n        long long ans=2;\n\n        sort(it.begin(), it.end());\n        for (int i = 1; i < n; i++) {\n            if (it[i][0] <= it[i - 1][1]) {\n                it[i][0] = it[i - 1][0];\n                if (it[i][1] <= it[i - 1][1])\n                    it[i][1] = it[i - 1][1];\n            } else{\n                  cnt++;\n                  ans=((ans%mod)*2)%mod;\n            }\n                \n        }\n        // long long ans=pow(2,cnt);\n        return ans%mod;\n    }\n};\n```
['Sorting', 'C++']