C++ O(NlogN) DP solution || commented
\nclass Solution {\npublic:\n    #define ll long long\n    int countWays(vector<vector<int>>& ranges) {\n        sort(ranges.begin(),ranges.end());\n        vec
```\nclass Solution {\npublic:\n    #define ll long long\n    int countWays(vector<vector<int>>& ranges) {\n        sort(ranges.begin(),ranges.end());\n        vector<ll> dp(ranges.size(),0);\n        dp[0]=2;  //we can place the first interval in any group\n        int maxi=ranges[0][1];\n        for(int i=1;i<ranges.size();i++)\n        {\n            //if it overlaps with any of previous intervals then we have same ways\n            if(ranges[i][0]<=maxi)\n                dp[i]=dp[i-1];\n            else\n                dp[i]=2*dp[i-1];  //we can place current range in any group (2 ways)\n            maxi=max(maxi,ranges[i][1]);\n            dp[i]%=1000000007;\n        }\n        return dp[ranges.size()-1];\n    }\n};\n```\n\n**please upvote if this found helpful**
['Dynamic Programming', 'C++']