O(n log n) Soln
Complexity\n- Time complexity:O(nlogn)\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# 
# Complexity\n- Time complexity:$$O(nlogn)$$\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``` rust []\nimpl Solution {\n    pub fn count_ways(mut ranges: Vec<Vec<i32>>) -> i32 {\n        ranges.sort_unstable();\n        const m: u64 = 1_000_000_007;\n        let (mut res, mut last_known_end) = (1_u64, -1);\n        for range in ranges {\n            if range[0] > last_known_end {\n                //increase the number of buckets\n                res = (res * 2) % m;\n                last_known_end = range[1];\n            } else { last_known_end = last_known_end.max(range[1]); }\n        }\n        res as _\n    }\n}\n```\n``` java []\nclass Solution {\n    public int countWays(final int[][] ranges) {\n        Arrays.sort(ranges, Comparator.comparingInt(a -> a[0]));\n        final int MOD = 1_000_000_007;\n        long res = 1;\n        int lastKnownEnd = -1;\n\n        for (final int[] range : ranges) \n            if (range[0] > lastKnownEnd) {\n                res = (res * 2) % MOD;\n                lastKnownEnd = range[1];\n            } else lastKnownEnd = Math.max(lastKnownEnd, range[1]);\n        return (int) res;\n    }\n}\n```\n``` python []\nclass Solution:\n    def countWays(self, ranges: List[List[int]]) -> int:\n        ranges.sort()\n        MOD, res, last_known_end = 1_000_000_007, 1, -1\n        for start, end in ranges:\n            if start > last_known_end: \n                last_known_end = end\n                res = (res * 2) % MOD\n            else: last_known_end = max(last_known_end, end)\n        return res\n```\n``` scala []\nobject Solution {\n    def countWays(ranges: Array[Array[Int]]): Int = \n        ranges\n        .sortBy(_(0))\n        .foldLeft((1L, -1)) { \n            case ((res, lastEnd), Array(start, end)) =>\n            if start > lastEnd then ((res * 2) % 1_000_000_007, end)\n            else (res, lastEnd.max(end))\n        }\n        ._1\n        .toInt\n}\n```\n```golang []\nfunc countWays(ranges [][]int) int {\n    sort.Slice(ranges, func (i, j int) bool {\n        return ranges[i][0] < ranges[j][0]\n    })\n\n    const m uint64 = 1_000_000_007\n    res, lastKnownEnd := uint64(1), -1\n    \n    for _, r := range ranges{\n        if r[0] > lastKnownEnd {\n            res = (res * 2) % m\n            lastKnownEnd = r[1]\n        } else {\n            if r[1] > lastKnownEnd {\n                lastKnownEnd = r[1]\n            }\n        }\n    }\n\n    return int(res)\n}\n```
['Java', 'Go', 'Python3', 'Scala', 'Rust']