object FirstBadVersion extends App { // Replace this with the actual number of versions val totalVersions = 10 // Function to check if a version is bad (placeholder logic) def isBadVersion(version: Int): Boolean = { // Replace this with your actual logic to determine if a version is bad version >= 4 } def firstBadVersion(n: Int): Int = { var left = 1 var right = n while (left < right) { val mid = left + (right - left) / 2 if (isBadVersion(mid)) { right = mid // Search in the left half } else { left = mid + 1 // Search in the right half } } left // 'left' is the first bad version } // Find the first bad version val firstBad = firstBadVersion(totalVersions) println(s"The first bad version is $firstBad") }object FirstBadVersion extends App { def isBadVersion(version: Int): Boolean = { // Replace this with your logic to determine if a version is bad. // For demonstration, let's assume that versions 4 and above are bad. version >= 4 } def firstBadVersion(n: Int): Int = { var left = 1 var right = n while (left < right) { val mid = left + (right - left) / 2 if (isBadVersion(mid)) { right = mid // Search in the left half } else { left = mid + 1 // Search in the right half } } left // 'left' is the first bad version } val totalVersions = 10 // Replace with the total number of versions val firstBad = firstBadVersion(totalVersions) println(s"The first bad version is $firstBad") }