Easy Java Solution Using TreeMap & Merging Overlapping Intervals || Beats 89% ||
ApproachUse a TreeMap<> where:Key = left boundary (left) of an interval.
Value = right boundary (right) of an interval.
This allows efficient range merging by c
# Approach
Use a TreeMap<> where:

Key = left boundary (left) of an interval.
Value = right boundary (right) of an interval.
This allows efficient range merging by checking the nearest overlapping intervals in O(log N), where N is the number of stored intervals.

Implementation Steps
Use a TreeMap<Integer, Integer> to store intervals:
The key represents the left boundary.
The value represents the right boundary.

add(left, right) Merging Logic:
Find the first overlapping interval using floorEntry(right).
Find the next overlapping interval using higherEntry(left).
Merge all overlapping intervals into a new one.
Remove old intervals from the TreeMap and insert the merged interval.

count() Implementation:
Maintain a total count of covered integers.
Update the count when merging intervals.

# Complexity
- Time complexity:
O(logN)

- Space complexity:
O(N)

# Code
```java []
class CountIntervals {
    TreeMap<Integer, Integer> map; //Left and Right Margin of CountIntervals
    int totalCount; //Stores the unique integers from left to right
    public CountIntervals() {
        map = new TreeMap<>();
        totalCount = 0;
    }
    
    public void add(int left, int right) {
        //Find largest entry that is less than or equal to right to find overlapping interval
        Map.Entry<Integer, Integer> entry = map.floorEntry(right);
        while(entry != null && entry.getValue() >= left){
            int existingLeft = entry.getKey();
            int existingRight = entry.getValue();
            totalCount -= existingRight - existingLeft + 1;
            left = Math.min(existingLeft, left);
            right = Math.max(existingRight, right);
            //Remove existing one
            map.remove(existingLeft);
            //Initialize entry to next one lesser than newly created entry
            entry = map.floorEntry(right);
        }
        //At the end insert merged interval and update total count
        map.put(left, right);
        totalCount += right - left + 1;
    }
    
    public int count() {
        return totalCount;
    }
}

/**
 * Your CountIntervals object will be instantiated and called as such:
 * CountIntervals obj = new CountIntervals();
 * obj.add(left,right);
 * int param_2 = obj.count();
 */
```
['Ordered Map', 'Java']