Generate Array whose difference of each element with its left yields the given Array | Function to find the sequence ; Initializing 1 st element ; Creating sequence in terms of x ; Finding min element ; Finding value of x ; Creating original sequence ; Output original sequence ; Driver code
def find_seq ( arr , m , n ) : NEW_LINE INDENT b = [ ] NEW_LINE x = 0 NEW_LINE b . append ( x ) NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT b . append ( x + arr [ i ] + b [ i ] ) NEW_LINE DEDENT mn = n NEW_LINE for i in range ( n ) : NEW_LINE INDENT mn = min ( mn , b [ i ] ) NEW_LINE DEDENT x = 1 - mn NEW_LINE for i in range ( n ) : NEW_LINE INDENT b [ i ] += x NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT print ( b [ i ] , end = ' ▁ ' ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 3 NEW_LINE arr = [ - 2 , 1 ] NEW_LINE M = len ( arr ) NEW_LINE find_seq ( arr , M , N ) NEW_LINE DEDENT