✅✅ Simple Approach with Intuition✅  ✅
Intuition\nIt is a simple observation that one interval have 2 option either it can become part of first group or second group and if all the intervals are inde
# Intuition\nIt is a simple observation that one interval have 2 option either it can become part of first group or second group and if all the intervals are independent of each other i.e non overlapping then it will lead to  2^n possible ways of grouping the intervals but intervals can be overlaping and two overlapping intervals should remain in same group then it will decrease the possiblity by some factor.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\nLet say we have x intervals which are non - overlaping then these intervals can become part of first group or second group which will lead to 2 possiblities for each interval\n\n1 2 3 ..... x \n2 2 2 ..... 2 ( x times )\n\nwhich results in 2^x possiblities\n\n\nBut if there are x intervals which are overlaping then these intervals collectively can become part of either first group or second group hence the contribution of these x intervals will be only 2 .\n\n1 2 3 .... x -- > belong to Group 1\n1 2 3 .... x -- > belong to Group 2\n\nHence will contribute only 2 possibilites\n\n\nHence our approach will be simple . Sort the intervals in increasing order ( non - decreasing order ) and make a variable end . Intially our end will have value of first interval\'s end .\n\nNow there are two options \n\n1 ) If the ith interval have value less than end then it will be considered as overlapping to previous interval and thus don\'t contribute in answer .\n\n2 ) If the ith internal have value greater than end then it will not be overlapping with previous interval hence considered as independent interval so it will contribute to answer by a factor of 2 .\n\n\nIn both the cases we need to update the end to the maximum of previous or current interval\'s end .\n\nIn last we will multiply by 2 so that we can consider the last set of intervals . This will eventually gives us the answer.\n\n\n# Please upvote if you like this approach :)\n\n# Complexity\n- Time complexity\nO(nlogn)\n\n- Space complexity:\nO(1)\n# Code\n```\nclass Solution {\npublic:\n    int countWays(vector<vector<int>>& ranges) {\n       \n        long long ans = 1;\n        \n        sort( ranges.begin() , ranges.end());\n    \n        int end   = ranges[0][1];\n        \n        int mod = 1e9 + 7 ;\n        \n        \n        for( int i = 1 ; i < ranges.size() ; i++)\n        {\n            if( ranges[i][0] <= end)\n            {\n                 end = max( end , ranges[i][1] );\n            }\n            else\n            {\n                ans= (( ans%mod )*( 2 % mod )) %mod;\n                end = max( end , ranges[i][1]);\n            }\n        }\n\n        ans= (( ans%mod )*( 2 % mod )) %mod;\n        \n        return ans;\n    \n    }\n};\n```
['Sorting', 'C++']