Distinct absolute array elements

carnato

Vishal Yadav

Posted on January 22, 2022

Distinct absolute array elements

USing the unordered_set:

#include<bits/stdc++.h>
using namespace std;

int main()
{
   int arr[]={-3, -2, 0, 3, 4, 5};
   int n=6;
   unordered_set<int>us;
        int count=0;
        for(int i=0;i<n;i++)
        {
            us.insert(abs(arr[i]));
        }
        cout<<us.size();


    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