Save 25%Black Friday: 25% off all plans — use code BLACKFRIDAY2026 at checkout. Ends Friday, Dec 4.Claim the deal

Given a sorted array of integers (which may include duplicates) and a target value, implement a function to perform a binary search. If the target is present, return the index of its first occurrence. If the target is absent, return the index of the closest element that does not exceed the target.

Test Cases
Input
Output
Expected