Distinct Numbers CSES Solution with Explanation | CSES Problem Set

 

Distinct Numbers

You are given a list of n integers, and your task is to calculate the number of distinct values in the list.

Input

The first input line has an integer n: the number of values.

The second line has n integers x1,x2,,xn.

Output

Print one integers: the number of distinct values.

Constraints
  • 1n2105
  • 1xi109
Example

Input:
5
2 3 2 2 3


Output:
2

void solve() {
// n is the size of array
int n;
cin>>n;
// map to store the unique elements and its frequency
map<int,int>m;

for (int i = 0; i < n; i++)
{
    int x;
    cin>>x;
    m[x]++;
}
// total unique elements is the size of the map
cout<<m.size()<<endl;

}

Post a Comment

0 Comments