-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram17.cpp
More file actions
68 lines (54 loc) · 1.18 KB
/
program17.cpp
File metadata and controls
68 lines (54 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// program to check the unique occurence of elements
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool uniqueoccurencecheck(int arr[],int n){
vector<int>ans;
int size = n;
sort (arr,arr+n);
int i = 0;
while(i<size){
int count = 1;
for(int j = i+1;j<size;j++){
if(arr[i]==arr[j]){
++count;
}
else{
break;
}
}
i = i + count;
ans.push_back(count);
}
sort(ans.begin(),ans.end());
size = ans.size();
for(int i = 0;i<size-1;i++){
if(ans[i] == ans[i+1]){
return false;
}
}
return true;
}
int main(){
int n;
cout<<"Enter number of elements do you want to enter : ";
cin>>n;
int arr[n];
for(int i = 0;i<n;i++){
cin>>arr[i];
}
cout<<"your array is [";
for(int i = 0;i<n;i++){
cout<<arr[i]<<" , ";
}
cout<<"]"<<endl;
bool check = uniqueoccurencecheck(arr,n);
if(check){
cout<<"Occurence of each element is Unique "<<endl;
}
else{
cout<<"not Unique Occurence "<<endl;
}
return 0;
}