Sorting , Easy C++ Beats 95% ✅✅
Approach\n Describe your approach to solving the problem. \nSort the given intervals and calculate the number non-overlaping Intervals.\n\nif number of non over
# Approach\n<!-- Describe your approach to solving the problem. -->\n**Sort** the given intervals and calculate the **number non-overlaping Intervals**.\n```\nif number of non overlaping intervals  =  n\nnumber of possible groups = pow(2,n)\n```\n**Note:- Calculate the power of 2 manually instead of Pow() function.**\n# Complexity\n- Time complexity:O(N* log(N))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int countWays(vector<vector<int>>& r) {\n        sort(r.begin(),r.end());\n        int end = r[0][1],mod = 1e9+7;\n        long long ans = 1,count = 1;\n        for(int i = 0;i<r.size();i++)\n        {\n            if(end<r[i][0])\n            {\n                count++;\n                end = r[i][1];\n            }\n            else\n            end = max(end,r[i][1]);\n        }\n        for(int i = 0;i<count;i++)\n        ans = ((ans%mod)*2)%mod;\n        return ans%mod;\n    }\n};\n```\n![upvote.jpg](https://assets.leetcode.com/users/images/f9821fe1-e06c-4877-add8-99173de7da68_1689783328.0557287.jpeg)\n
['Sorting', 'C++']