← Bitkernel Interview Insights
I almost went with 1, 2, 3 because my brain defaulted to linear search logic.
Simulate the binary search step-by-step, clearly stating the initial low and high bounds, computing the midpoint using the given formula, and adjusting the bounds based on whether the target is less than or greater than the midpoint. Continue until the target is found, and record each examined index in order.
Pro tip: Mention that you're using 1-based indexing and the floor function for midpoint calculation, and double-check that your bounds are inclusive (low and high are valid indices). This shows attention to detail and avoids off-by-one errors.
Set low = 1 and high = 18, since the array has 18 elements and indexing is 1-based.
Calculate mid = floor((low + high) / 2). For the first iteration, mid = floor((1+18)/2) = 9.
Compare the target (position 3) with the element at mid. Since 3 < 9, set high = mid - 1 = 8. Record the examined index (9).
Continue the process: compute new mid, compare, and adjust bounds until the target index is examined. Record each mid in order.
After the search terminates, list all examined indices in the order they were checked.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.