Find when failures started in log stream
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates understanding of monotonic sequences and search algorithms (such as binary search), along with algorithmic reasoning about correctness and time-complexity.
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([(1,'OK'), (2,'OK'), (3,'FAIL'), (4,'FAIL')],)
Expected Output: 3
Explanation: Failure begins at timestamp 3.
Input: ([(1,'OK'), (2,'OK')],)
Expected Output: -1
Explanation: No failure.
Input: ([(5,'FAIL')],)
Expected Output: 5
Explanation: All fail.
Input: ([],)
Expected Output: -1
Explanation: Empty logs.
Hints
- Choose a representation that makes the requested operation direct.
- Handle empty inputs and boundary cases first.