Question: 
Write a python function to find the last position of an element in a sorted array.


Model's Code:
def last(arr, x, n):
    low, high = 0, n - 1
    result = -1
    while low <= high:
        mid = (low + high) // 2
        if arr[mid] == x:
            result = mid
            low = mid + 1
        elif arr[mid] < x:
            low = mid + 1
        else:
            high = mid - 1
    return result



Sample Correct Code:
def last(arr,x,n):
    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


Asserts:
assert last([1,2,3],1,3) == 0
assert last([1,1,1,2,3,4],1,6) == 2
assert last([2,3,2,3,6,8,9],3,8) == 3


Tests:
Test 1 of 3: PASS
Test 2 of 3: PASS
Test 3 of 3: PASS

Test 793 of 974: 602/793 (75.91424968474149%): success