Coders Crushby Napplied AI
Back to DSA Problems
EasyBinary Search

First Bad Version

Find first bad version

Solution Approach

Binary search to find first bad version. Set boundaries and narrow search space by checking middle version.

Implementation
def isBadVersion(n):
    left, right = 1, n
    while left < right:
        mid = (left + right) // 2
        if isBadVersion(mid):
            right = mid
        else:
            left = mid + 1
    return left
Complexity Analysis

Time Complexity

O(log n)

Space Complexity

O(1)
Complexity
Time:O(log n)
Space:O(1)
Asked at
GoogleFacebookUber
Coders Crushby Napplied AI

The ultimate interview preparation platform. Master System Design, DSA, and tackle community challenges to crush your FAANG interviews.

Looking for jobs? Visit Napplied AI Jobs Search Agent

System Design

  • All Problems
  • Easy
  • Hard

DSA

  • All Problems
  • Dynamic Programming
  • Graphs

More

  • Problems Arena
  • Growth Paths
  • My Crush

Coders Crush by Napplied AI - Tech Interview & Coding Should Be Effortless