Very easy Approach || Beats 100% || C++ || O(N)
Intuition\n Describe your first thoughts on how to solve this problem. \ni) Find the all Non overlapping intervals\nii) Then the total no. of ways to divide giv
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\ni) Find the all Non overlapping intervals\nii) Then the total no. of ways to divide given intervals in two groups is equal to 2^(no. of Non overlapping intervals)\niii) We count all the overlapping intervals as one as we have to group them in a single group\n\n\n\n\nEX- [1,3] , [2,4], [5,7], [6,8]\n=> \xA0[1,3] , [2,4] is considered as a Single Interval or single Class which contains two overlapping intervals.\nsame goes for [5,7], [6,8] - considered as a Single Interval or single Class.\n=> total count = 1+1 = 2 (non overlapping intervals)\n=> Ans = 2^2 = 4\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\ni) Sort the given vector and then compare the pair of intervals from left to right using a loop. maintain a rem variable (remaining non overlapping intervals) intialize with 0.\n\n\nii) Maintain a temp variable and initialise it with !st interval end point - It should always save the maximum value of the previous and current interval end point.\n\n\niii)\xA0If there is is a interval that is Non Overlapping then the curr interval start will surely be > prev interval end(temp) => increment the rem in this case\n\n\niv) Do rem++ after the loop ends, as it has not counted the last non overlapping interval. \xA0\n\n\nv) now finally return the 2^(ans);\n# Complexity\n- Time complexity:O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n\n# Code\n```\n/*\n\n\nclass Solution {\npublic:\n\xA0 \xA0 int mod = 1e9+7;\n\xA0 \xA0 int countWays(vector<vector<int>>& ran) {\n\xA0 \xA0 \xA0 \xA0 sort(ran.begin(), ran.end());\n\xA0 \xA0 \xA0 \xA0 int c = 0;\n\xA0 \xA0 \xA0 \xA0 int temp = ran[0][1], rem = 0;\n\xA0 \xA0 \xA0 \xA0 for(int i=1; i<ran.size(); i++){\n\xA0 \xA0 \xA0 \xA0 \xA0 \xA0 if(temp < ran[i][0]) rem++;\n\xA0 \xA0 \xA0 \xA0 \xA0 \xA0 temp = max(temp, ran[i][1]);\n\xA0 \xA0 \xA0 \xA0 }\n\xA0 \xA0 \xA0 \xA0 rem++;//for last non overlapping intervals\n\xA0 \xA0 \xA0 \xA0 int i=0, ans = 1;\n\xA0 \xA0 \xA0 \xA0 while(i<rem){\n\xA0 \xA0 \xA0 \xA0 \xA0 \xA0 ans = 2*ans;\n\xA0 \xA0 \xA0 \xA0 \xA0 \xA0 ans = ans % mod;\n\xA0 \xA0 \xA0 \xA0 \xA0 \xA0 i++;\n\xA0 \xA0 \xA0 \xA0 }\n\xA0 \xA0 \xA0 \xA0 return ans;\n\xA0 \xA0 }\n};\n```
['C++']