Find True-to-False Transition Index
Given a boolean array where the first element is always true and the last element is always false, find and return any index i such that arr[i] is true and arr[i+1] is false. Your solution must run in O(log n) time and O(1) space.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Early May, 2026
You are given a boolean array arr of length n (where n >= 2). The array is guaranteed to follow two specific conditions: 1. The first element is always true (arr[0] == true). 2. The last element is always false (arr[n-1] == false). The values between the first and last elements can appear in any order. Your task is to find and return any index i such that arr[i] is true and arr[i+1] is false. Constraints * Time Complexity: O(log n) * Space Complexity: O(1) * The array may contain multiple such transitions; returning the index of any valid transition is acceptable. Example 1 Input: arr = [true, false, false, false, false, true, true, false] Output: 0 or 6 Example 2 Input: arr = [true, true, true, false] Output: 2 Do you need the O(log n) solution written out in a specific programming language to go with this statement?
Hello Interview Premium
Your account is free and you can post anonymously if you choose.