human
Integers from the range that are composed of a single distinct digit | Function to return the count of digits of a number.
Function to return a number that contains only digit ' d ' repeated exactly count times.
Function to return the count of integers that are composed of a single distinct digit only.
Count of digits in L and R.
First digits of L and R.
If L has lesser number of digits than R.
If the number that starts with firstDigitL and has number of digits = countDigitsL is within the range include the number.
Exclude the number.
If the number that starts with firstDigitR and has number of digits = countDigitsR is within the range include the number.
Exclude the number.
If both L and R have equal number of digits.
Include the number greater than L upto the maximum number whose digit = coutDigitsL.
Exclude the numbers which are greater than R.
Return the count.
Driver code"
Solution in Python:
 Give me a code to integers from the range that are composed of a single distinct digit and the other steps required?
assistant
#Here is code to integers from the range that are composed of a single distinct digit and the other steps required.
 def countDigits ( n ) :
	count = 0
	while ( n > 0 ) :
		count += 1
		n //= 10
	return count
def getDistinct ( d , count ) :
	num = 0
	count = pow ( 10 , count - 1 )
	while ( count > 0 ) :
		num += ( count * d )
		count //= 10
	return num
def findCount ( L , R ) :
	count = 0
	countDigitsL = countDigits ( L )
	countDigitsR = countDigits ( R )
	firstDigitL = ( L // pow ( 10 , countDigitsL - 1 ) )
	firstDigitR = ( R // pow ( 10 , countDigitsR - 1 ) )
	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
L = 10
R = 50
print ( findCount ( L , R ) )