[Java] Merge Using Stack || Count
\nclass Solution {\n    public int countWays(int[][] ranges) {\n        Arrays.sort(ranges, (a, b) -> {\n            if (a[0] == b[0]) {\n                return
```\nclass Solution {\n    public int countWays(int[][] ranges) {\n        Arrays.sort(ranges, (a, b) -> {\n            if (a[0] == b[0]) {\n                return a[1] - b[1];\n            }\n            return a[0] - b[0];});\n        System.out.print(Arrays.deepToString(ranges));\n\n        Stack<int[]> stack = new Stack<>();\n        stack.push(ranges[0]);\n\n        for (int i = 1; i < ranges.length; i++) {\n            if (ranges[i][0] <= stack.peek()[1] && ranges[i][1] >= stack.peek()[0]) {\n                int[] previous = stack.pop();\n                stack.push(new int[]{Math.min(previous[0], ranges[i][0]), Math.max(previous[1], ranges[i][1])});\n            }\n            else {\n                stack.push(ranges[i]);\n            }\n        }\n        long ans = 1;\n        long n = stack.size();\n        while (n > 0) {\n\n            ans = (ans * 2) % 1000000007;\n            n--;\n        }\n\n        return (int) ans;\n    }\n}\n```
[]