You are building an in-memory alert analytics component. Each alert has:
timestamp
(integer seconds since epoch)
severity
(one of a small fixed set, e.g.,
INFO/WARN/ERROR/CRITICAL
)
Implement data structures / APIs to support the following:
countRecent(now)
returns the number of alerts with timestamps in
.
severityDist(now)
returns a map
severity -> count
for alerts whose timestamps fall within the current hour window
(or
if you prefer full-hour reporting—state your assumption).
cnt[0..n-1]
where
cnt[i]
is the number of alerts in minute
i
, compute an array
nextHigher[0..n-1]
where:
nextHigher[i]
is the smallest index
j > i
such that
cnt[j] > cnt[i]
j
exists,
nextHigher[i] = -1