It is given that, $A$ and $B$ each select one number at random from the distinct numbers $1,2 , 3, \ldots, n$, then the probability that the number
selected by $A$ is less than the number selected by $B$ is
$ \frac{{ }^{n} C_{2}}{n \times n}=\frac{n(n-1)}{2(n \times n)}=\frac{1009}{2019} $ (given)
$\Rightarrow \frac{n-1}{2 n}=\frac{1009}{2019}$
$ \Rightarrow 2019 n-2019=2018 n$
$\Rightarrow n =2019$
Now, number of ways selecting numbers from the distinct numbers $1,2,3, \ldots, 2019$, by $B$ is the number immediately next to the number selected by $A$ is 2018 , because there are 2018 pairs of consecutive numbers.
So, required probability $=\frac{2018}{2019 \times 2019}$
$=\frac{2018}{(2019)^{2}}$