Remove temporary element

 // Online C++ compiler to run C++ program online

#include <iostream>

#include <climits>

using namespace std;


int remove_duplicate(int* arr, int n){

    for (int i=0;i<n;i++){

        int x=arr[i];

        for(int j=i+1;j<n;j++){

            if (arr[j]==x){

                arr[j]=INT_MIN;

            }

        }

    }

    int x=INT_MIN;

    for(int i=0;i<n;i++){

        if (arr[i]==x){

            for(int j=i;j<n;j++){

                arr[j]=arr[j+1];

            }

            n--;

        }

    }

    cout<<n<<endl;

    for(int i=0;i<n-1;i++){

        cout<<arr[i]<<" ";

    }

    cout<<endl;

    return n-1;

    

}


int main() {

    int arr[50]={10,20,20,30,30,30};

    int n=6;

    cout<<remove_duplicate(arr,n);


    return 0;

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings