Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

implementing function for frequency count #1306

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions algorithms/CPlusPlus/Arrays/freqcount.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 10;
int hshp[N];
int hshn[N];

int main()
{
int q;
int x;
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
{

cin >> a[i];
if (a[i] < 0)
{
hshn[abs(a[i])]++;
}
else
{
hshp[a[i]]++;
}
}
cin >> q;
while (q--)

{
cin >> x;
if (x < 0)
{
cout << hshn[abs(x)];
}
else
{
cout << hshp[x] << endl;
}
}
}

// hash array