Distinct absolute array elements
Vishal Yadav
Posted on January 22, 2022
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;
}
💖 💪 🙅 🚩
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.