First Bad Version
First Bad Version
Hello, little detective! Imagine you're helping a team of magical toy makers to identify which batch of toys started causing trouble. You have a series of toy versions, and everything was perfect until one bad version appeared and every later version turned out to be bad too.
Your mission is to write a Python function that helps us find the first bad version as quickly as possible. Suppose you have n versions represented as integers, 1 through n, and you have a helper function is_bad_version(version) that will return True if the version is bad and False if it's good.
Here's the challenge: You need to find the very first bad version among all toy versions. The versions are arranged such that every version after a bad version is also bad.
Example
Let's say you have several versions of toys, and the bad version starts at 4:
# Assume the following function exists for the purpose of this challenge
def is_bad_version(version: int) -> bool:
return version >= first_bad_version
Now, if we call find_first_bad_version(5, 4), it should return 4 because that is the first version where toys started being bad.
find_first_bad_version(5, 4) # returns 4 find_first_bad_version(3, 4) # returns None (if all are good)
Your Task
Write a function find_first_bad_version(n: int, first_bad_version: int) -> int: that returns the first bad version number, or returns None if all versions are good.
Good luck, young detective! The toy makers are counting on you!
Inputs
Arg 1:
5Arg 2:
4Expected Output
4Actual Output