Inserting two groups of blanks into a string Let x be a string of length n, and let y be a string of length n − k, for
1 ≤ k < n.
We wish to line up the symbols in x with the symbols in y by adding k blanks to y.
Suppose that we add two separate blocks of blanks, one of size i and one of size
k − i,
for
1 ≤ i < k.
How many ways are there to do this?
I am not really sure were to start for this problem. I understand that if we wanted to input a continue block it would result in n-k+1.
 A: You are correct in thinking that there are $n-k+1$ ways to add a single block of $k$ blanks, as it can start at any position from $1$ through $n-k+1$. Now you need to compute the number of ways to insert a block of $i$ blanks and a block of $k-i$ blanks so that the blocks are not adjacent. One reasonably easy way to do this is to let $\ell$ be the number of characters between the two blocks of blanks, so that $1\le\ell\le n-k$, so that the combined length of the two blocks and the characters separating them is $k+\ell$, and then count the possibilities for each possible value of $\ell$.
A block of $k+\ell$ characters can start at any position $j$ such that
$$1\le j\le n-(k+\ell)+1\,,$$
so it has $n-(k+\ell)+1$ possible starting points. Now, unfortunately, there are two possibilities. If the two blocks of blanks are of different lengths, i.e., if $i\ne k-i$, there are two possibilities: either the $i$ block comes first, then the $\ell$ characters between the blocks, and then the $k-i$ block, or the $k-i$ block comes first and the $i$ block last. Thus, there are exactly two possible positions for the $\ell$ block separating the two blocks of blanks, and each possible starting point for the whole block of $k+\ell$ characters gives rise to $2$ different placements of the two blocks of blanks. This means that if $i\ne k-i$, there are
$$\begin{align*}
2\sum_{\ell=1}^{n-k}(n-k+1-\ell)&=2\sum_{\ell=1}^{n-k}(n-k+1)-2\sum_{\ell=1}^{n-k}\ell\\
&=2(n-k)(n-k+1)-2\cdot\frac{(n-k)(n-k+1)}2\\
&=2(n-k)(n-k+1)-(n-k)(n-k+1)\\
&=(n-k)(n-k+1)
\end{align*}$$
ways to insert the two blocks of blanks so that they are not adjacent. As you said, there are $n-k+1$ ways to insert a single block of $k$ blanks, so we get a total of
$$(n-k)(n-k+1)+(n-k+1)=(n-k+1)^2$$
possibilities if $i\ne k-i$.
If $k=k-i$, so that the two blocks of blanks are the same size, the calculation is a little different, because there is only one possible location for the $\ell$ characters between the two blocks. I’ll leave it to you to work out the details for this case.
A: The first part is pretty straightforward. You have n-k+1 blanks, so the answer is n-k+1.
The second part is tricky but yet still straightforward. Now you have two blocks to put down. First we consider the way to put down the first block, it's still n-k+1 ways. Now, we consider how many ways to put down the second block. Notice, after you put down the first block, this new sequence will have n-k+1 blanks, (I treat the first new block as a whole), so you should have n-k+1+1 ways to put down the second block. So the answer is (n-k+1)(n-k+1+1)=(n-k+1)(n-k+2) ways.
