PracHub
QuestionsLearningGuidesInterview Prep
|Home/Coding & Algorithms/Qualcomm

Find the First Bad Version in a Monotonic Release History

Last updated: Jul 22, 2026

Quick Overview

Find the earliest bad entry in a monotonic release history, returning -1 when every version is good. This compact coding prompt tests boundary-safe binary search, empty and all-good inputs, first-element failures, loop invariants, and logarithmic performance on histories with up to a million versions.

  • medium
  • Qualcomm
  • Coding & Algorithms
  • Software Engineer

Find the First Bad Version in a Monotonic Release History

Company: Qualcomm

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

# Find the First Bad Version in a Monotonic Release History You are given a release history as a boolean array `bad`. Versions use zero-based indices. Once a bad version appears, every later version is also bad, so the array has the form `False, ..., False, True, ..., True`. Return the index of the first bad version. Return `-1` if every version is good. ## Function Signature ```python def first_bad_version(bad: list[bool]) -> int: ... ``` ## Constraints - `0 <= len(bad) <= 1_000_000` - `bad` is monotonic: no `False` value appears after a `True` value. - The implementation should remain efficient when the history is very large. ## Examples ```text Input: bad = [False, False, True, True, True] Output: 2 ``` ```text Input: bad = [False, False] Output: -1 ``` ```text Input: bad = [True] Output: 0 ```

Quick Answer: Find the earliest bad entry in a monotonic release history, returning -1 when every version is good. This compact coding prompt tests boundary-safe binary search, empty and all-good inputs, first-element failures, loop invariants, and logarithmic performance on histories with up to a million versions.

Related Interview Questions

  • Compute the Diameter of an Undirected Tree - Qualcomm (medium)
  • Implement A* Maze Search - Qualcomm (medium)
|Home/Coding & Algorithms/Qualcomm

Find the First Bad Version in a Monotonic Release History

Qualcomm logo
Qualcomm
Apr 16, 2026, 12:00 AM
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
1
0

Find the First Bad Version in a Monotonic Release History

You are given a release history as a boolean array bad. Versions use zero-based indices. Once a bad version appears, every later version is also bad, so the array has the form False, ..., False, True, ..., True.

Return the index of the first bad version. Return -1 if every version is good.

Function Signature

def first_bad_version(bad: list[bool]) -> int:
    ...

Constraints

  • 0 <= len(bad) <= 1_000_000
  • bad is monotonic: no False value appears after a True value.
  • The implementation should remain efficient when the history is very large.

Examples

Input: bad = [False, False, True, True, True]
Output: 2
Input: bad = [False, False]
Output: -1
Input: bad = [True]
Output: 0

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

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

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

Product

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

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.