cpp

Sum of Distinct Element

carnato

Vishal Yadav

Posted on January 22, 2022

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
πŸ’– πŸ’ͺ πŸ™… 🚩
carnato
Vishal Yadav

Posted on January 22, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related