You are given a sorted array of integers nums that may contain duplicate elements, and a target integer target, your task is to find the index of the first occurrence of the target.
If the target is not found in the array, you should return -1.
You must write an algorithm that is more efficient than a linear search.
nums = [1, 3, 3, 3, 3, 6, 10, 10, 10, 10]
target = 3
1
The number 3 appears multiple times. The first occurrence is at index 1.
nums = [2, 4, 10, 10, 10, 18, 20]
target = 10
2
The first occurrence of 10 is at index 2.
nums = [1, 2, 3, 4, 5]
target = 6
-1
The target 6 is not present in the array.
nums = [1, 3, 3, 3, 3, 6, 10, 10, 10, 10]
target = 3
1