Solution based on counting overlapping intervals
Approach\nSolution based on counting overlapping intervals \n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution {
# Approach\nSolution based on counting overlapping intervals \n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n    int countWays(vector<vector<int>>& ranges) {\n        std::sort(ranges.begin(), ranges.end(),\n                  [&](const vector<int>& a, const vector<int>& b) { return a[0] < b[0]; });\n\n        long result = 2;\n        int right = ranges[0][1];\n\n        for (int i = 1; i < ranges.size(); i++) {\n            if (ranges[i][0] > right) {\n                result *= 2;\n                result %= 1000000007;\n            }\n\n            if (ranges[i][1] > right) {\n                right = ranges[i][1];\n            }\n        }\n\n        return result;\n    }\n};\n```
['C++']