How to
Find Missing Number
In Array
by interviewspreparation.com/
Welcome back, visitors. 'Find missing number questions' are intermediate problems commonly asked in interviews.
by interviewspreparation.com/
int maxNumber = 0;
int totalOfArrayElements = 0;
for (int i = 0; i < questionArray.Length; i++)
{
if (maxNumber < questionArray[i])
{
maxNumber = questionArray[i];
}
totalOfArrayElements += questionArray[i];
}
by interviewspreparation.com/
int mainTotal = 0;
for (int i = 0;i <= maxNumber;i++)
{
mainTotal += i;
}
output = mainTotal - totalOfArrayElements;
by interviewspreparation.com/
by interviewspreparation.com/
To understand how it is working follow our website
Learn more