i for which arr[i] == target.-1 when no element equals the target.Implement the judged function using this exact signature:
def find_rightmost_index(arr, target):
Input: arr = [0, 1, 1, 4, 4, 7], target = 4
Output: 4
The target appears at indices 3 and 4, so the final occurrence is at index 4.
Input: arr = [2, 3, 6, 8, 10], target = 5
Output: -1
Because 5 is absent from the array, there is no valid matching index.
Input: arr = [-3, -1, -1, -1, 2], target = -1
Output: 3
The three matching values occupy indices 1 through 3, making 3 the rightmost match.
[2, 5, 5, 5, 9] with target = 5; it should return index 3. Record lo, hi, and mid after every loop iteration.