Find original sequence from Array containing the sequence merged many times in order | Function that returns the restored permutation ; List to store the result ; Map to mark the elements which are taken in result ; Checking if the element is coming first time ; Push in result vector ; Mark it in the map ; Return the answer ; Function to print the result ; Driver code ; Given array ; Function call
def restore ( arr , N ) : NEW_LINE INDENT result = [ ] NEW_LINE mp = { } NEW_LINE for i in range ( N ) : NEW_LINE INDENT if not arr [ i ] in mp : NEW_LINE INDENT result . append ( arr [ i ] ) NEW_LINE mp [ arr [ i ] ] = 1 NEW_LINE DEDENT DEDENT return result NEW_LINE DEDENT def print_result ( result ) : NEW_LINE INDENT for i in range ( len ( result ) ) : NEW_LINE INDENT print ( result [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT def main ( ) : NEW_LINE INDENT arr = [ 1 , 13 , 1 , 24 , 13 , 24 , 2 , 2 ] NEW_LINE N = len ( arr ) NEW_LINE print_result ( restore ( arr , N ) ) NEW_LINE DEDENT main ( ) NEW_LINE