Array problem

please help:-
How to count all distinct elements in an array in c++ ???

You can use an std :: unordered_set, std :: set, or even a count array if the constraints permit you to do so.

int count_unique(int a[], int n) {
      unordered_set<int> st;
      for(int i=0; i<n; i++) {
            st.insert(a[i]);
      }
      return st.size();
}

This should solve your problem.
Cheers.

1 Like

ARRAY PROBLEM
Why have you created new thread?

Because i thought that my previous thread didn’t post