From e52adb163a62d8c20e4cf2f3ac384c838e418cfd Mon Sep 17 00:00:00 2001 From: Sai Lalitha Sunaina Madgula Date: Sat, 25 Oct 2025 16:30:52 -0400 Subject: [PATCH] Competitive-Coding-1 Competitive-Coding-1 --- Problem1.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Problem1.java b/Problem1.java index 8b137891..dc51aef8 100644 --- a/Problem1.java +++ b/Problem1.java @@ -1 +1,22 @@ +// 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. + +class Solution { + int missingNumber(int[] arr, int n) { + int low = 0, high = n - 2; // since size = n-1 + + while (low <= high) { + int mid = low + (high - low) / 2; + + // Expected value at mid index = mid + 1 + if (arr[mid] == mid + 1) + low = mid + 1; + else + high = mid - 1; + } + + return low + 1; // the missing number + } +}