PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates understanding of monotonic sequences and search algorithms (such as binary search), along with algorithmic reasoning about correctness and time-complexity.

  • medium
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Find when failures started in log stream

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

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: - At some time `T` (possibly never), a failure begins. - **Once a failure begins, every log at time ≥ T has status `FAIL`** (i.e., the statuses are a prefix of `OK`s followed by a suffix of `FAIL`s). ### Task 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`). ### Edge cases to consider - Empty log array - All logs are `OK` - All logs are `FAIL` ### Complexity goal Better than linear time if possible.

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.

Given monotonic OK...FAIL logs, return the first FAIL timestamp or -1 if no failure exists.

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

  1. Choose a representation that makes the requested operation direct.
  2. Handle empty inputs and boundary cases first.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Minimum Path Length Through a Grid With One Allowed Cell Conversion - Amazon (medium)
  • Circular Drone Hub Delivery Route - Amazon (hard)
  • Leaf Domain Cumulative Scores - Amazon (medium)
  • Kth Largest Perfect Binary Subtree - Amazon (medium)
  • Find Conflicting Events - Amazon (medium)