 However, it is sometimes necessary to find the leftmost element or the rightmost element for a target value that is duplicated in the array.In the above example, the 4th element is the leftmost element of the value 4, while the 5th element is the rightmost element of the value 4.The alternative procedure above will always return the index of the rightmost element if such an element exists.