We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e792498 commit 4de89e8Copy full SHA for 4de89e8
hashing.cpp
@@ -0,0 +1,21 @@
1
+// Hashing help us to count the frequency of an element in the array in time complexity of O(N). so this is
2
+// an efficient method for calculating the frequency of an element in array
3
+
4
5
+#include<bits/stdc++.h>
6
+using namespace std;
7
+const long long int M=1e5+5;
8
+int main(){
9
+int n; //size of the array
10
+cin>>n;
11
+int a[n];
12
+int hash_arr[M];
13
+for(int i=0;i<M;i++)hash_arr[i]=0;
14
+for(int i=0;i<n;i++){
15
+ cin>>a[i];
16
+ hash_arr[a[i]]++;
17
+}
18
+int x; // Number whose frequency we want
19
+cin>>x;
20
+cout<<hash_arr[x];
21
hashing.exe
45.8 KB
0 commit comments