DEV Community

Vishal Yadav
Vishal Yadav

Posted on

3 3

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

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs