DEV Community

Vishal Yadav
Vishal Yadav

Posted on

Sum of Distinct Element

Solution

#include<bits/stdc++.h>
using namespace std;
void fun(int arr[],int n,int k)
{

}
int main()
{
   int arr[42];
   int n=42;
   for(int i=0;i<n;i++)
   cin>>arr[i];
unordered_map<int,int>mp;
        for(int i=0;i<n;i++)
        {
            mp[arr[i]]++;
        }
        int sum=0;
       for(auto it:mp)
       {
           sum+=it.first;
       }

   cout<<sum;

    return 0;
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)