st0le
4/26/2013 - 5:00 AM

Find Gap in Sorted Array - Binary Search

Find Gap in Sorted Array - Binary Search


def find_first_gap(lst, low , high):
    if high - low == lst[high] - lst[low]: return -1
    if low + 1 == high: return lst[low] + 1
    mid = (low + high) / 2
    if mid - low < lst[mid] - lst[low]: #gap in first half
        return find_first_gap(lst,low,mid)
    else:
        return find_first_gap(lst,mid,high)