java sol
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\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```\nclass Solution {\n    public int countWays(int[][] ranges) {\n      \n        Arrays.sort(ranges, Comparator.comparingInt(a -> a[0]));\n\n        Stack<int[]> stack = new Stack<>();\n        stack.push(ranges[0]);\n\n        for(int i=1;i<ranges.length;i++){\n\n            int[] current = ranges[i];\n            int[] top = stack.peek();\n            int[] arr = new int[2];\n\n            if(top[1]>=current[0]){\n\n                if(!stack.isEmpty()){\n                    stack.pop();\n                }\n\n                arr[0]=top[0];\n\n                arr[1] = top[1]>=current[1]?top[1]:current[1];\n\n                stack.push(arr);\n\n            }\n            else {\n                stack.push(current);\n            }\n\n        }\n\n\n        return qpow(2, stack.size(), (int) 1e9 + 7);\n\n    }\n\n     private int qpow(long a, int n, int mod) {\n        long ans = 1;\n        for (; n > 0; n >>= 1) {\n            if ((n & 1) == 1) {\n                ans = ans * a % mod;\n            }\n            a = a * a % mod;\n        }\n        return (int) ans;\n    }\n}\n```
['Java']