Print all numbers from a given range that are made up of consecutive digits | Function to find the consecutive digit numbers in the given range ; Initialize num as empty string ; Stores the resultant number ; Iterate over the range [ 1 , 9 ] ; Check if the current number is within range ; Iterate on the digits starting from i ; Checking the consecutive digits numbers starting from i and ending at j is within range or not ; Sort the numbers in the increasing order ; Driver Code ; Print the required numbers
def solve ( start , end ) : NEW_LINE INDENT num = " " NEW_LINE ans = [ ] NEW_LINE for i in range ( 1 , 10 , 1 ) : NEW_LINE INDENT num = str ( i ) NEW_LINE value = int ( num ) NEW_LINE if ( value >= start and value <= end ) : NEW_LINE INDENT ans . append ( value ) NEW_LINE DEDENT for j in range ( i + 1 , 10 , 1 ) : NEW_LINE INDENT num += str ( j ) NEW_LINE value = int ( num ) NEW_LINE if ( value >= start and value <= end ) : NEW_LINE INDENT ans . append ( value ) NEW_LINE DEDENT DEDENT DEDENT ans . sort ( ) NEW_LINE return ans NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT L = 12 NEW_LINE R = 87 NEW_LINE ans = solve ( 12 , 87 ) NEW_LINE for it in ans : NEW_LINE INDENT print ( it , end = " ▁ " ) NEW_LINE DEDENT DEDENT