human
Write a python function to find the last position of an element in a sorted array. Here is a solution in Python: What is a Python code to find the last position of an element in a sorted array?
assistant
#Here is Python code to find the last position of an element in a sorted array.
 def last(arr,x):
    n = len(arr)
    low = 0
    high = n - 1
    res = -1  
    while (low <= high):
        mid = (low + high) // 2 
        if arr[mid] > x:
            high = mid - 1
        elif arr[mid] < x:
            low = mid + 1
        else:
            res = mid
            low = mid + 1
    return res