You are given an array of log entries sorted by timestamp ascending. Each log entry contains:
timestamp
(monotonic increasing)
status
∈ {
OK
,
FAIL
}
Assume the system behaves as follows:
T
(possibly never), a failure begins.
FAIL
(i.e., the statuses are a prefix of
OK
s followed by a suffix of
FAIL
s).
Return the earliest timestamp (or index) at which failure started (the first FAIL in the array). If there is no failure, return a sentinel value (e.g., null / -1).
OK
FAIL
Better than linear time if possible.