একটি অ্যারেতে যেসব উপাদানের ফ্রিকোয়েন্সি ১ এর বেশি সেগুলো বের করতে হবে। উদাহরণ: {1,5,2,5,3,1,5,2,7} → ১ (২ বার), ৫ (৩ বার), ২ (২ বার)। আউটপুট: {1,5,2}
অ্যালগরিদম
moreFreq(arr, n)
Begin define map for each e in arr do increase map[e] done for each key if map[key] > 1 then print key End
উদাহরণ
#include <iostream> #include <map> using namespace std; void moreFreq(int arr[], int n){ map<int,int> freq_map; for(int i=0; i<n; i++) freq_map[arr[i]]++; for (auto it=freq_map.begin(); it!=freq_map.end(); it++) { if (it->second > 1) cout << it->first << " "; } } int main() { int arr[] = {1,5,2,5,3,1,5,2,7}; int n = sizeof(arr)/sizeof(arr[0]); cout << "Frequency more than one: "; moreFreq(arr, n); }আউটপুট
Frequency more than one: 1 2 5