Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
296 B
5
Indexable
Never
s = arr[x] + arr[y]
low = y + 1
high = len(arr) - 1
mid = (low + high) // 2

while low <= high:
    if arr[mid] == s:
        break
    elif arr[mid] < s:
        low = mid + 1
    else:
        high = mid - 1
    mid = (low + high) // 2

k += mid - y
if s <= arr[mid]:
    k -= 1
Leave a Comment