<script>
function
countDigits(n)
{
let count = 0;
while
(n > 0)
{
count += 1;
n = parseInt(n / 10, 10);
}
return
count;
}
function
getDistinct(d, count)
{
let num = 0;
count = parseInt(Math.pow(10, count - 1), 10);
while
(count > 0)
{
num += (count * d);
count = parseInt(count / 10, 10);
}
return
num;
}
function
findCount(L, R)
{
let count = 0;
let countDigitsL = countDigits(L);
let countDigitsR = countDigits(R);
let firstDigitL = parseInt(L / parseInt(Math.pow(10,
countDigitsL - 1), 10), 10);
let firstDigitR = parseInt(R / parseInt(Math.pow(10,
countDigitsR - 1), 10), 10);
if
(countDigitsL < countDigitsR)
{
count += (9 * (countDigitsR - countDigitsL - 1));
if
(getDistinct(firstDigitL, countDigitsL) >= L)
count += (9 - firstDigitL + 1);
else
count += (9 - firstDigitL);
if
(getDistinct(firstDigitR, countDigitsR) <= R)
count += firstDigitR;
else
count += (firstDigitR - 1);
}
else
{
if
(getDistinct(firstDigitL, countDigitsL) >= L)
count += (9 - firstDigitL + 1);
else
count += (9 - firstDigitL);
if
(getDistinct(firstDigitR, countDigitsR) <= R)
count -= (9 - firstDigitR);
else
count -= (9 - firstDigitR + 1);
}
return
count;
}
let L = 10, R = 50;
document.write(findCount(L, R));
</script>