Learner Level
Implement the method firstOccurrence that returns the first index of a target value in a sorted array.
Given a sorted integer array, return the first zero-based index where target appears.
The task is designed to test careful handling of edge cases, not only the most common input.
- Use only the first
sizeelements. - The array may contain duplicate values.
- Return
-1when the target is missing.
Use binary search. When a match is found, store it and keep searching the left half.