🚀️🔥️ Kotlin beats 100% - O(n*log(n)) with sorting
Approach\nSort ranges by start, then keep track of the max range end up to index i. If the range at index i overlaps the max, then we\'ll just update the max. E
# Approach\nSort ranges by start, then keep track of the max range end up to index i. If the range at index i overlaps the max, then we\'ll just update the max. Else there is another range which means we must increase count of different range groups.\n\nThe answer is multiplied by 2 because every time we find a non overlapping range, we foud a new group of independent ranges.\n\nWe can create 2 groups of n different ranges 2^n different ways.\n\n# Complexity\n- Time complexity:\n$$O(n*log(n))$$ \n\n- Space complexity:\n$$O(1)$$ \n\n# Code\n```\nimport kotlin.math.pow\nclass Solution {\n    fun countWays(ranges: Array<IntArray>): Int {\n        ranges.sortBy { it[0] }\n        var rangesCount = 1\n        var lastRange = ranges[0][1]\n        var ans = 2\n\n        for (i in 1 until ranges.size) {\n            if (lastRange < ranges[i][0]) {\n                ans = (ans * 2) % 1000000007    \n            }\n            \n            lastRange = maxOf(lastRange, ranges[i][1])\n        }\n        return ans\n    }\n}\n```
['Sorting', 'Kotlin']