Read the Big-O
Sorted Pair Sum
values is sorted with n items. Two pointers walk towards each other: how does the time grow?1def pair_exists(values, key):
2 lo, hi = 0, len(values) - 1
3 while lo < hi:
4 s = values[lo] + values[hi]
5 if s == key:
6 return True
7 if s < key:
8 lo += 1
9 else:
10 hi -= 1
11 return False