Mid From PDF Coding C# Coding Interview

Find Missing Number in Sorted Array of Distinct?

Integers
int FindMissingNumber(int[] nums)
{
int low = 0, high = nums.Length - 1;

while (low <= high)

{
int mid = low + (high - low) / 2;
if (nums[mid] == mid)
low = mid + 1;

else

high = mid - 1;
}
return low;
}

Explanation:

In perfect array nums[i] == i; missing number breaks this property, use binary search to find

breakpoint.

Mathematical Problems

More from C# Programming Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details