PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Amazon

Find when failures started in log stream

Last updated: Apr 15, 2026

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.

Related Interview Questions

  • Find Unique Target-Sum Pairs - Amazon (easy)
  • Find Valid IP Addresses in Files - Amazon (medium)
  • Implement Optimal Bucket Batching - Amazon (hard)
  • Implement Cache and Rotate Matrix - Amazon (medium)
  • Find Longest Activatable Server Streak - Amazon (hard)
Amazon logo
Amazon
Jan 22, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
3
0
Loading...

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.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Amazon•More Software Engineer•Amazon Software Engineer•Amazon Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ 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
  • Compare Platforms
  • Discord Community

Support

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

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.