From 6317ed848a50728c82117797441c77215c8f38d1 Mon Sep 17 00:00:00 2001 From: Manassa2000 Date: Wed, 8 Oct 2025 16:13:58 -0400 Subject: [PATCH] Competitive-Coding-1 --- Problem1.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Problem1.java b/Problem1.java index 8b137891..2ae31cbb 100644 --- a/Problem1.java +++ b/Problem1.java @@ -1 +1,27 @@ +//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 +// Before the missing element: arr[i] == i+1 +// After the missing index: arr[i] == i+2 +// So the missing number is i+1 at the first index where this occurs. + + +class Problem1{ + int missingNumber(int arr[]){ + int low,high,mid; + low=0; + high = arr.length-1; + while(low<=high){ + mid=low+(high-low)/2; + if(arr[mid]==mid+1){ + low=mid+1;//missing element is in right side + } + else{ + high=mid-1;//missing element is in left side + } + } + return low+1; + } +}