what is smallest possible value of range of $7$ values given that their mean is $12$ and their median is $9$ 
what is smallest  possible  value  of range of $7$ values given that their mean is $12$ and their median is $9$ :-
a) $3$
B) $6$
C) $7$
D) $8$

What is the proper approach to solve this problem , is there any relation or inquality that help ? What if we need the largest possible value? 
Thank you for your help 

List the numbers in order: $a_1\le a_2\le a_3\le a_4\le a_5\le a_6\le a_7$.
You know the median is 9, so you now have $a_1,a_2,a_3,9,a_5,a_6,a_7$
The mean is $12$, so you know that $7\times 12=84=a_1+a_2+a_3+9+a_5+a_6+a_7$.
So $a_1+a_2+a_3+a_5+a_6+a_7=75$
You want $a_7-a_1$ to be as small as possible. This means you want $a_1,a_2,a_3,a_5,a_6$ to be assigned with values as large as possible and $a_7$ to be as small as possible.
The maximum for $a_1,a_2,a_3$ is $9$. This leaves $a_5+a_6+a_7=48$. You want $a_7$ as small as possible, and this occurs when $a_5=a_6=a_7$. So set them to $16$.
Now you have as your list $9,9,9,9,16,16,16$.
This gives $7$ as the answer.

In general, let's say you wanted to find the smallest range of the finite set $\{a_k \in \mathbb R, k\in\{1,...,n\}: i<j \implies a_i\le a_j\}$ which has mean $\mu$ and median $m$. If $n = 1$ or $2$, then the answer is $0$ unless $\mu \neq m$, in which case no such set is possible.
$n$ is odd $\implies$ Using the same reasoning as before, you assign $a_k=m$ for $k\lt \frac{n+1}{2}$ (and we know that $a_{\frac{n+1}{2}}=m$).
Using the mean,
$$n\mu=\sum^n_{k=1}{a_k}=\frac{n+1}{2}m+\sum^n_{k=\frac{n+3}{2}}{a_k}$$
$\implies$
$$\sum^n_{k=\frac{n+3}{2}}{a_k}=n\mu-\frac{n+1}{2}m$$
Again, using the same reasoning as before, you let $a_\frac{n+3}{2}=a_\frac{n+5}{2}=...=a_{n}$.
So the range is
$$a_n-a_1=\frac{n\mu-\frac{n+1}{2}m}{\frac{n-1}{2}}-m$$
$$=\frac{n\mu-mn}{\frac{n-1}{2}}$$
$$=2(\mu-m)\frac{n}{n-1}$$
Testing this with the above example gives $2(12-9)\frac{7}{6}=7$.
$n$ is even $\implies$ The average of the middle two numbers is the median. However, you want the smallest one of them as large as possible, as you later want to make all of the numbers smaller than it as large as possible. This happens when the middle two numbers are equal.
So we have $a_{\frac{n}{2}}=a_{\frac{n+2}{2}}=m$ assign $a_k=m$ for $k\lt \frac{n}{2}$.
Using the mean,
$$n\mu=\sum^n_{k=1}{a_k}=\frac{n+2}{2}m+\sum^n_{k=\frac{n+4}{2}}{a_k}$$
$\implies$
$$\sum^n_{k=\frac{n+4}{2}}{a_k}=n\mu-\frac{n+2}{2}m$$
As before, let $a_\frac{n+4}{2}=a_\frac{n+6}{2}=...=a_{n}$.
The range is
$$a_n-a_1=\frac{n\mu-\frac{n+2}{2}m}{\frac{n-2}{2}}-m$$
$$=\frac{n\mu-mn}{\frac{n-2}{2}}$$
$$=2(\mu-m)\frac{n}{n-2}$$

You can write this as $2(\mu-m)\frac{n}{2\lfloor\frac{n-1}{2}\rfloor}$ for all $n\ge 3$.
