Combinatorics || Line Sweep || Modular Exponentiation || Math || Cpp
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)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\nlong long modexp(long long base, long long exp, long long mod) {\n    long long result = 1;\n    base %= mod;\n    while (exp > 0) {\n        // If exp is odd, multiply result with base and take mod\n        if (exp & 1) {\n            result = (result * base) % mod;\n        }\n        // Reduce exp by half and square base (base^2) modulo mod\n        base = (base * base) % mod;\n        exp >>= 1; // Equivalent to exp /= 2\n    }\n    return result;\n}\n    int countWays(vector<vector<int>>& a) {\n        \n         int n=a.size();\n         int mod=1e9+7;\n         map<int,int> m;\n         for(auto& x:a)\n         {\n            m[x[0]]++;\n            m[x[1]]--;\n         }\n         int count=0;\n         int ans=0;\n         for(auto& x:m)\n         {\n            count+=x.second;\n            if(count==0)\n             ans++;\n         }\n       \n       cout<<ans<<endl;\n       return (int)modexp(2,ans,mod);\n    }\n};\n```
['Math', 'Line Sweep', 'Combinatorics', 'C++']