Pick $$ boxes from $$ boxes while $$ boxes picked are consecutive in location. How many combinations exist? I have an array of $m$ boxes. I want to pick $n$ boxes from this array, but I require that at least $k$ boxes of the picked boxes are consecutive in location. $m \geq n \geq k$. How many combinations that meet the requirements exist?
 A: First please take a pen and paper so that you can follow the reasoning.
First we pick the $k$ boxes which are consecutive. Notice that the choice of the first box which should start the consecutive chain automatically selects all the other boxes. How many ways are there to do this? Notice that we don't have $m$ choices because then there won't be enough boxes ahead of the first boxes. So we have only $m-k+1$ choices so that all the boxes may fit. Now there are $m-k$ choices and $n-k$ boxes yet to be chosen. Now it is normal to think that there are ${m-k \choose n-k}*(m-k+1)$ and close the problem. But we still have to consider some edge cases. When the first box in the consecutive chain is between the $1^{st}$ and $m-k^{th}$ box(inclusive), the remaining boxes must be chosen as follows:
The remaining $n-k$ boxes can only be chosen from $m-k-2$ choices because there will be two additional boxes that may not be chosen or else the consecutive boxes will be more than $k$.So the total number of ways in this case is ${m-k-2 \choose n-k}*(m-k)$.
In the second case the first box in the consecutive chain is the $m-k+1^{th}$ box. In this case the remaining $n-k$ boxes can only be chosen from the maximum $m-k-1$ choices because there will be one additional box that may not be chosen or else the consecutive boxes will be more than $k$.(In this case it is only one extra box which is not allowed because one box is already at the end of the row and there are no boxes to the right of it).So in this case there are ${m-k-1 \choose n-k}*1$.(Here we multiplied by one because there is only $1$ such case. Adding the two up there are, in total:
$(({m-k-2 \choose n-k}*(m-k))$$+$$({m-k-1 \choose n-k}*1)$
Hope this helps!
