All of the digits from $0$ to $9$ are used to form two $5$-digit numbers. What is the smallest possible difference between these two numbers?
For this, I have come up with answer as
Two $5$-digit numbers as $01234$ and $56789$ and the difference for the same is $55555$. is this right?
We want $$(10000a_1+1000b_1+100c_1+10d_1+e_1)-(10000a_2+1000b_2+100c_2+10d_2+e_2)$$ or $$10000(a_1-a_2)+1000(b_1-b_2)+100(c_1-c_2)+10(d_1-d_2)+(e_1-e_2)$$ Firstly, we want to minimize the largest term, so we want $a_1$ and $a_2$ to be as close together as possible. This means that $a_1$ and $a_2$ must be consecutive with $a_1>a_2$.
Next, to minimize the second term, we must have $b_1-b_2<0$ so ensure carrying. This time, we want the largest difference so $b_1=0$ and $b_2=9$.
Finally we want the hundred, tens and unit terms to be as far apart as possible. So we could have $c_1=1$, $d_1=2$, $e_1=3$ and $c_2=9$, $d_2=8$, and $e_2=7$.
This leaves $a_1=5$ and $a_2=4$ so the smallest difference is: $$\boxed{50123-49876=247}$$