networking · intermediate · ~15 min
Track a high-water mark.
Using the same connect/disconnect log, report the high-water mark — the maximum number of clients connected simultaneously at any point. Knowing peak concurrency sizes your connection table and worker pool.
Implement int peak_connections(const char *ops) that returns the maximum running connection count reached while processing ops ('c' = connect, 'd' = disconnect, with the count floored at 0).
A string ops of 'c' and 'd' characters.
Returns the peak simultaneous connection count.
peak_connections("cccddc") -> 3
peak_connections("cdcd") -> 1
A string ops of 'c' (connect) and 'd' (disconnect) characters.
The maximum simultaneous connection count reached.
Maintain a running count (floored at 0) and remember its maximum.
int peak_connections(const char *ops) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.