Question:
Missing Bowl
There are N bowls arranged on a table in a row. Each bowl
contains some marbles in such a way that the sum of the
number of marbles in the first and the last bowl is equal to
the sum of the number of marbles in the second and the
second last bowl, and so forth. The bowls are kept in the
increasing order of the number of marbles in it.
After some time, it is found that there are only N-1 bowls.
The first and the last bowls are at their positions, but one
of the bowls in between has gone missing
Find the number of marbles in the missing bowl, given
that N%2==0
Answers
Answered by
110
Answer:
public int MissingMarbles(int number, int[] bowls)
{
int sum = bowls[0] + bowls[number - 1];
int missing = 0;
int i = 1, j = number - 2;
while(i<=j)
{
if(bowls[i]+bowls[j] == sum)
{
i++;
j = j - 1;
}
else
{
if (i == j)
missing = sum - bowls[i];
else
missing = (sum - (bowls[i] + bowls[j]));
break;
}
}
return missing;
}
Explanation:
Similar questions