Design a stateful sliding-window event analyzer in TypeScript where a stream of { userId, timestamp } events (possibly out of order) is ingested and a user is considered active if they have at least one event in the last W milliseconds; the solution maintains a FIFO buffer of events plus a Map<string, number> storing each user’s latest timestamp, so ingest runs in O(1) by appending and updating the map, while getActiveUserCount(now) evicts expired events incrementally using a moving head pointer and removes users only when their last-seen timestamp falls outside the window, yielding O(1) amortized time, bounded memory by window size, no re-scans or sorting, and cleanly supporting high-throughput real-time analytics.