Question d’entretien chez Jane Street

Variants on binary search

Réponse à la question d'entretien

Utilisateur anonyme

30 nov. 2015

you mean "invariants"? ``` def binsearch(target, arr): lo, hi = 0, len(arr)-1 while lotarget: hi=mid-1 else: lo = mid+1 return -1 ``` invariant for binsearch is that after each while loop, the result (if exists) should be between lo and hi.