Skip to content
Open

done #1313

Show file tree
Hide file tree
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
Binary file added .DS_Store
Binary file not shown.
23 changes: 23 additions & 0 deletions Problem1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
We check if the difference between the number and the index is not 1, then we return the shift the right pointer and left pointer accordingly to the condition
the SC for this is O(1) ad tc is o(logn) due to binary search
"""


# #find missing integer in array of 1 to n

def solution(arr):
left = 0
right = len(arr) - 1

while right - left > 1:
mid = left + (right - left) // 2
if arr[left] - left != arr[mid] - mid:
right = mid
else:
left = mid
return arr[left] + 1 #since answer is gauranteed to be there

arr = [1, 2, 3, 5, 6, 7]
print(solution(arr))