From e9ba1e319633586638758ef27b64077cc8f179bb Mon Sep 17 00:00:00 2001 From: Shinjanee Gupta Date: Mon, 16 Feb 2026 20:08:07 -0800 Subject: [PATCH] Missing number problem --- MissingNumber.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 MissingNumber.py diff --git a/MissingNumber.py b/MissingNumber.py new file mode 100644 index 00000000..aa686fb0 --- /dev/null +++ b/MissingNumber.py @@ -0,0 +1,20 @@ +# Time Complexity : O(log n) +# Space Complexity : O(1) +# Did this code successfully run on Leetcode : Yes +# Any problem you faced while coding this : No +# Approach : Use binary search to find the index where low and high indices cross each other. + +class Solution: + def missingNumber(self, arr): + + low, high = 0, len(arr) - 1 + + while low <= high: + mid = low + (high - low) // 2 + + if arr[mid] <= (mid + 1): + low = mid + 1 + else: + high = mid - 1 + + return low + 1 \ No newline at end of file