**Summarize**

`This is to find the maximum number of concurrent ongoing event at any time.`

We can log the `start`

& `end`

of each event on the timeline, each `start`

add a new ongoing event at that time, each `end`

terminate an ongoing event. Then we can scan the timeline to figure out the maximum number of ongoing event at any time.

**Java**

```
class MyCalendarThree {
private TreeMap<Integer, Integer> times = new TreeMap<>();
public int book(int s, int e) {
times.put(s, times.getOrDefault(s, 0) + 1); // 1 new event will be starting at times[s]
times.put(e, times.getOrDefault(e, 0) - 1); // 1 new event will be ending at times[e];
int ongoing = 0, k = 0;
for (int v : times.values())
k = Math.max(k, ongoing += v);
return k;
}
}
```

**C++**

```
class MyCalendarThree {
map<int, int> times;
public:
int book(int s, int e) {
times[s]++; // 1 new event will be starting at times[s]
times[e]--; // 1 new event will be ending at times[e];
int ongoing = 0, k = 0;
for (pair<int, int> t : times)
k = max(k, ongoing += t.second);
return k;
}
};
```