Given a sorted array of the elements [1,2,3] and the target element 1. The target element 1 occurs first and last at position 0. The output is the last occurrence of the target element 1, i.e. position 0. Given a sorted array of the elements [1,1,1,2,3,4] and the target element 1. The target element 1 occurs first at position 0 and last at position 2. The output is the last occurrence of the target element 1, i.e. position 2. Given a sorted array of the elements [2,3,2,3,6,8,9] and the target element 5. The target element 5 does not occur in the input array. The output is -1.
[[1,2,3],1] [[1,1,1,2,3,4],1] [[2,3,2,3,6,8,9],5]
0 2 -1