leetle

Daily challenge for 2026-06-05

521. Find the First Defective Batch

You are given a sorted array of integers batches where each integer represents the quality score of a product batch. A batch is considered defective if its score is strictly less than a given threshold limit. Since the array is sorted in ascending order, all defective batches will appear at the beginning. Use binary search to find the index of the first batch that is NOT defective (i.e., its score is >= limit). If all batches are defective, return the length of the array.

Example:
Input: batches = [10, 20, 30, 40, 50], limit = 35
Output: 3
Explanation: The batch at index 3 has a score of 40, which is the first score >= 35.

Run this challenge interactively in Python or JavaScript when the app loads.