[JavaScript] 2580. Count Ways to Group Overlapping Ranges
---\n\n# Intuition\n- Do merge interval algorithm, since overlapping should be merged\n- Do something with length of merged interval\n  - May be powerset size, 
---\n\n# Intuition\n- Do merge interval algorithm, since overlapping should be merged\n- Do something with length of merged interval\n  - May be powerset size, due to two groups\n- Add BigInt & do MOD as needed in problem description\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n\n```\nvar merge = (intervals) => {\n    intervals.sort((a, b) => a[0] - b[0]);\n\n    const ans = [[...intervals[0]]];\n    for (let [start, end] of intervals) {\n        const prevEnd = ans[ans.length - 1][1];\n        if (prevEnd >= start) {\n            ans[ans.length - 1][1] = Math.max(prevEnd, end);\n        } else {\n            ans.push([start, end]);\n        }\n    }\n\n    return ans;\n};\n\nvar countWays = function (intervals) {\n    intervals = merge(intervals);\n\n    let two = BigInt(2);\n    let n = BigInt(intervals.length);\n    let MOD = BigInt(10 ** 9 + 7);\n\n    return two ** n % MOD;\n};\n```\n\n---\n\n- Above code is from my contest submission\nLink - https://leetcode.com/contest/biweekly-contest-99/ranking/53/\n\n![image.png](https://assets.leetcode.com/users/images/cf69d900-93d0-4edb-b639-086a9906e2d4_1677964098.6619318.png)\n\n\n- Rating change:\nLink - https://lccn.lbao.site/predicted/biweekly-contest-99\n\n![image.png](https://assets.leetcode.com/users/images/9852a5eb-62df-42cc-969d-403d99c3e5db_1677965024.9956195.png)\n\n---\n\n## Biweekly Contest 99 answers\n\n- Q1 - https://leetcode.com/problems/split-with-minimum-sum/solutions/3257467/javascript-2578-split-with-minimum-sum/?orderBy=most_votes\n- Q2 - https://leetcode.com/problems/count-total-number-of-colored-cells/solutions/3257488/javascript-2579-count-total-number-of-colored-cells/?orderBy=most_votes\n- Q3 - https://leetcode.com/problems/count-ways-to-group-overlapping-ranges/solutions/3257499/javascript-2580-count-ways-to-group-overlapping-ranges/?orderBy=most_votes\n\n---\n
['JavaScript']