The question goes like this… given n coins 1,2,3…n kept in a row. You have to pick M coins from these N coins such that C connected components are left
A part [a,b] of sequence is called a connected component if for all a <= i <= b there is a coin at position i and also there are no marbles at positions a-1 and b+1 (either because those marbles have been removed or because they are out of range [1,N] ).
My approach is this:
Lets assume that the ith connected component has xi coins in it. Now some of all the left out coins should be n-m. So the equation we get is :-
Then i just took the positive solutions of this equation as my final answer.
Apparently this method is wrong and I am not able to figure it out why.
Please help me finding the mistake. Thanks!