I have $n$ books, $k$ of which are my favorites. I randomly place the books on a shelf (so that any of the $n$ books' orderings is equally likely). For what value of $k$ will the probability be maximal, and for what value will it be minimal, that the $k$ favorite books end up next to each other when placed on the shelf?
We can arrange $n$ books on a shelf in $n!$ different ways. To count the favorable cases, we can imagine tying our favorite books together before arranging them. The resulting unit, along with the other $(n-k)$ books, can be placed on the shelf in $(n-k+1)!$ different orders. Before tying, the order of the favorite books can be arranged in $k!$ ways, so the number of favorable cases is $k!(n-k+1)!$. Thus, the probability we are looking for is:

$$
P(k)=\frac{k!(n-k+1)!}{n!}
$$

This equals one - and thus is maximal - when $k=1$ or $k=n$. To determine the minimum, let's examine for which values of $k$ we have $P(k)>P(k+1)$. Since

$$
\frac{P(k)}{P(k+1)}=\frac{k!(n-k+1)!}{(k+1)!(n-k)!}=\frac{n-k+1}{k+1}
$$

$P(k)$ is greater than $P(k+1)$ if and only if $(n-k+1)>(k+1)$, which is the case if $2k<n$. Therefore, $P(k)$ is decreasing for $k<\frac{n}{2}$ and increasing for $k>\frac{n}{2}$. If $n$ is odd, the minimum occurs at $k=\frac{n-1}{2}$ and $k=\frac{n+1}{2}$. If $n$ is even, the minimum occurs at $k=\frac{n}{2}$. The condition $P(k)>P(k+1)$ for $k<\frac{n}{2}$ and $P(k)<P(k+1)$ for $k>\frac{n}{2}$ suggests that $n>1$, and the maximum occurs only when $k=n$.

If $n$ is even, the condition $P(1)>P(2)$ and $P(n-1)<P(n)$ suggests that $n>1$, and the maximum occurs only when $k=n$.