Make the list non | Python3 implementation of the approach ; Function to return the minimum element from the range [ prev , MAX ] such that it differs in at most 1 digit with cur ; To start with the value we have achieved in the last step ; Store the value with which the current will be compared ; Current value ; There are at most 4 digits ; If the current digit differs in both the numbers ; Eliminate last digits in both the numbers ; If the number of different digits is at most 1 ; If we can 't find any number for which  the number of change is less than or  equal to 1 then return -1 ; Function to get the non - decreasing list ; Creating a vector for the updated list ; Let 's assume that it is possible to  make the list non-decreasing ; Element of the original array ; Can 't make the list non-decreasing ; If possible then print the list ; Driver code
DIGITS = 4 ; MIN = 1000 ; MAX = 9999 ; NEW_LINE def getBest ( prev , cur ) : NEW_LINE INDENT maximum = max ( MIN , prev ) ; NEW_LINE for i in range ( maximum , MAX + 1 ) : NEW_LINE INDENT cnt = 0 ; NEW_LINE a = i ; NEW_LINE b = cur ; NEW_LINE for k in range ( DIGITS ) : NEW_LINE INDENT if ( a % 10 != b % 10 ) : NEW_LINE INDENT cnt += 1 ; NEW_LINE DEDENT a //= 10 ; NEW_LINE b //= 10 ; NEW_LINE DEDENT if ( cnt <= 1 ) : NEW_LINE INDENT return i ; NEW_LINE DEDENT DEDENT return - 1 ; NEW_LINE DEDENT def getList ( arr , n ) : NEW_LINE INDENT myList = [ ] ; NEW_LINE possible = True ; NEW_LINE myList . append ( 0 ) ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT cur = arr [ i ] ; NEW_LINE myList . append ( getBest ( myList [ - 1 ] , cur ) ) ; NEW_LINE if ( myList [ - 1 ] == - 1 ) : NEW_LINE INDENT possible = False ; NEW_LINE break ; NEW_LINE DEDENT DEDENT if ( possible ) : NEW_LINE INDENT for i in range ( 1 , len ( myList ) ) : NEW_LINE INDENT print ( myList [ i ] , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( " - 1" ) ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1095 , 1094 , 1095 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE getList ( arr , n ) ; NEW_LINE DEDENT