Skip to content
Open
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
20 changes: 20 additions & 0 deletions Problem1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Solution:
def missingNumber(self, arr):
# code here
if len(arr) == 1:
return len(arr)

low, high = 0 , len(arr)-1
while low < high:
mid = (low+high)//2
#verify left half
if arr[mid] == mid+1: #O(c)
low = mid + 1
else: #verify right half
high = mid - 1

if (low == 0 and arr[low] == 1) or arr[low] == low+1:
return arr[low] + 1

return arr[low] - 1

18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# Competitive-Coding-1

Please submit the interview problems posted in slack channel here. The problems and statements are intentionally not shown here so that students are not able to see them in advance

Missing Number in Sorted Array of Natural Numbers
Difficulty: EasyAccuracy: 55.26%Submissions: 2K+Points: 2
Given a sorted array arr[] of n-1 integers, these integers are in the range of 1 to n. There are no duplicates in the array. One of the integers is missing in the array. Find the missing integer.

Examples:

Input: arr[] = [1, 2, 3, 4, 6, 7, 8]
Output: 5
Explanation: The missing integer in the array is 5.
Input: arr[] = [1, 2, 3, 4, 5, 6, 8, 9]
Output: 7
Explanation: The missing integer in the array is 7.
Constraints:
1 ≤ arr.size() ≤ 105
1 ≤ arr[i] ≤ arr.size()+1