Find original sequence from Array containing the sequence merged many times in order | C # program for the above approach ; Function that returns the restored permutation ; List to store the result ; Set to insert unique elements ; Check if the element is coming first time ; Push in result vector ; Function to print the result ; Driver Code ; Given Array ; Function call
using System ; using System . Collections . Generic ; class GFG { static List < int > restore ( int [ ] arr , int N ) { List < int > result = new List < int > ( ) ; int count1 = 1 ; HashSet < int > s = new HashSet < int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { s . Add ( arr [ i ] ) ; if ( s . Count == count1 ) { result . Add ( arr [ i ] ) ; count1 ++ ; } } return result ; } static void print_result ( List < int > result ) { for ( int i = 0 ; i < result . Count ; i ++ ) Console . Write ( result [ i ] + " ▁ " ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 13 , 1 , 24 , 13 , 24 , 2 , 2 } ; int N = arr . Length ; print_result ( restore ( arr , N ) ) ; } }