blob: a8927d6c5d6e1b9310482b0758db2ca467374e76 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
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
|