Beats 100% || Easy || Sorting|| Binary Exponentiation
Intuition\n Describe your first thoughts on how to solve this problem. \nIf there are n distinct pairs then the no of ways they can be arranged in the required 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIf there are n distinct pairs then the no of ways they can be arranged in the required way is 2^n. When say x pairs are overlapping , all of them need to be in the same group . Therefore, x pairs are equivalent to 1 pair. Thus we find the no of those extra pairs and then calculate the effective no of distinct pairs by subtracting from n. \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe *find()* function is used to count the number of overlapping ranges in the given set of ranges. It does so by first sorting the ranges in ascending order based on their start values. It then iterates over the sorted ranges, keeping track of the last value seen. If the current range\'s start value is less than or equal to the previous range\'s end value or if it is equal to the last value seen, it means that the current range overlaps with the previous range and thus belongs to the same group. In this case, the function increments a counter. Otherwise, it updates the last value seen to the current range\'s end value. At the end of the loop, the function returns the counter value which represents the number of overlapping ranges.\n\nThe *countWays()* function uses the result of the find() function to compute the number of ways in which the ranges can be split into two groups. It subtracts the number of overlapping ranges from the total number of ranges to get the number of non-overlapping ranges. It then uses exponentiation by squaring to compute 2 raised to the power of the number of non-overlapping ranges. This gives the total number of ways to split the ranges into two groups such that no two overlapping ranges belong to different groups.\n\n# Complexity\n- Time complexity: O(nlog(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 find(vector<vector<int>>& ranges){\n        int c=0;\n        int last=-1;\n        sort(ranges.begin(),ranges.end());\n        for(int i=0;i<ranges.size();i++){\n            if(i!=0&&(ranges[i][0]<=ranges[i-1][1]||last>=ranges[i][0])){\n                c++;\n            }\n            last=max(last,ranges[i][1]);\n        }\n        return c;\n    }\n    int countWays(vector<vector<int>>& ranges) {\n        int overlapping=find(ranges);\n        cout <<overlapping;\n        long long int x=2;\n        int y=ranges.size()-overlapping;\n        long long int ans =1;\n        while(y>0){\n            if(y&1){\n                ans=(ans*x)%1000000007;\n            }\n            x=(x*x)%1000000007;\n            y=y>>1;\n        }\n        return ans%1000000007;\n    }\n};\n```
['C++']