White Board Solution - [Sorting & Power of 2 🔥] || Merge Intervals also explained
Video Solution\nhttps://www.youtube.com/watch?v=-3QJGBmbK5w\n\n# Intuition & Explanation\n Describe your first thoughts on how to solve this problem. \n\n\n\n\n
# Video Solution\nhttps://www.youtube.com/watch?v=-3QJGBmbK5w\n\n# Intuition & Explanation\n<!-- Describe your first thoughts on how to solve this problem. -->\n![image.png](https://assets.leetcode.com/users/images/92de9083-2d0b-4291-a0ac-ac3ec7bc3fcb_1677951210.7596238.png)\n![image.png](https://assets.leetcode.com/users/images/51c67aaa-b1f5-4509-b0c2-ed546347b2b1_1677951223.4262962.png)\n![image.png](https://assets.leetcode.com/users/images/49aeb49c-e8d6-40a4-be7c-570602be29a5_1677951231.362553.png)\n![image.png](https://assets.leetcode.com/users/images/b7f9976a-4d75-4d09-849c-4f536b027ac9_1677951239.6584918.png)\n![image.png](https://assets.leetcode.com/users/images/0cec5394-8018-4da1-ad77-0697af1569c2_1677951251.026729.png)\n![image.png](https://assets.leetcode.com/users/images/02531841-2738-41ab-bcaa-8ae75dfc3c21_1677951258.8241725.png)\n\n\n\n# Code\n```\n#define mod 1000000007\n#define ll long long int\n\nclass Solution {\npublic:\n    \n    // It means a^n % p\n    ll power(ll a, ll n, ll p){\n       ll res = 1;\n        while(n){\n            if(n%2 == 1){\n                res = (res * a)%p;\n                n--;\n            }else{\n                a = (a * a)%p;\n                n = n/2;\n            }\n        }\n        return res;\n    }\n    \n    int countWays(vector<vector<int>>& ranges) {\n        ll ans = 0;\n        \n        sort(ranges.begin(), ranges.end());\n        \n        vector<vector<int>> temp;\n        temp.push_back({ranges[0]});\n        for(int i=1;i<ranges.size();i++){\n            int last_fir = temp[temp.size()-1][0];\n            int last_val = temp[temp.size()-1][1];\n            \n            if(ranges[i][0] > last_val){\n                temp.push_back(ranges[i]);\n            }else{\n                temp.pop_back();\n                int final_last = max(last_val, ranges[i][1]);\n                temp.push_back({last_fir, final_last});\n            }\n        }\n        ans = power(2, temp.size(), mod);\n        \n        return (int)ans;\n        \n    }\n};\n```
['C++']