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 
 A: 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$.
A: Since the number of values is odd, you know that the median has to be one of the values (rather than the average of the two middle values, which would be the case in a list of even cardinality). Therefore the middle number (of an ascending ordered list) is $9$.
That means three numbers less than or equal to $9$ and three greater than or equal to $9$ on either side of the median value in the ordered list.
To restrict the range to a minimum, you can let the three numbers on the lower side all be $9$ themselves. The sum of the four nines is $36$. The total of all numbers is $(12)(7) = 84$, which means we have to make up a "deficit" of $48$.
The most parsimonious way to do this is to have the three remaining numbers all be sixteens. If you made any of the numbers lower than $16$, you will need a largest number greater than $16$, which will increase the range of the whole list.
So the list is $9,9,9,9,16,16,16$ and the range is $7$. Choice C.
Answering your other question: "what if the largest possible range were asked for?", there's no answer that can be given without imposing further conditions.
If any real number were allowed in the list of $7$ values, then I can just choose an arbitrarily highly negative value (just as an example, $-10^{100}$) as the smallest value, with the largest value $10^{100}$ chosen to exactly offset that. The third value from the left will have to be $9$. Then just pick the other four values to cluster around the $9$ value and also meet the required conditions for their overall sum to be $75$. So your list of seven (again, just an example) can be $-10^{100}, -10, 0, 9, 10, 75, 10^{100}$. Your range is now $2 \times 10^{100}$.  It's a purely artificial construction, you can make it as large as you like.
If you're only allowed non-negative integers for the values, then you can come up with a more sensible construction. In this case, the optimal list for maximum range would be $0,0,0,9,9,9,57$ and the range is $57$. I think you should be able to use the principles I've described to see why this is the answer in this scenario.
A: You have seven numbers.  Let's call them $a, b, c, d, e, f, g$ where $a \le b \le c \le d \le e \le f \le g$.
You know that the median is 9, so $d = 9$.
You know that the mean is 12, so $a + b + c + d + e + f + g = 12 \times 7 = 84$.
The range is $g - a$ and you want that to be as small as possible.  So start by making $a$ as large as possible, namely 9; then $a = b = c = d = 9$.
You now have $e + f + g = 84 - (4 \times 9) = 48$ - so how small can $g$ be, given that it's the largest of $e, f,$ and $g$?
