Implement a search over a sorted integer array. Return the index of the target or -1 when it is absent. Then adapt your implementation to return the lower-bound insertion position and explain which comparison changes.
Acceptance criteria
- Empty input and a one-element array behave correctly.
- Duplicate values have a documented result policy.
- The search range shrinks on every iteration.
- Explain why the input must be sorted and why
lo + (hi - lo) / 2avoids a bounded-integer overflow.
Use the linked judge for the original challenge. Before submitting, trace the interval after each comparison on a target below the first element, between values, and above the last element.