Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions missing_num_in_sorted_arr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class solution(object):
def missing_number_bs(self, arr):

low, high = 0, len(arr) - 1
while low <= high:
mid = (low + high) // 2
expected = mid + 1
if arr[mid] == expected:
low = mid + 1 # missing is to the right
else:
high = mid - 1 # missing is to the left (or here)

return low + 1 # the missing number