Housing party question

here is a question I am unable to solve
can someone help me out pls language that can be used is c++
The original family in the town has organised a homecoming party with N people invited Each person has a special trust value denoted by Array A . A person i will be friends with person j only if either A[i]%A[j]==0 or A[j]%A[i]==0. Find maximum no of friends each person can make and return the array
i/p
2 3 4 5 6
o/p
2 1 1 0 2

1 Like

can be solved in nlogn with hashing,
use a map to store the frequencies of the elements and then iterate on multiples of distinct numbers in the array till they dont cross the maximum element and add the frequency stored in the map for that particular multiple

sure will try

use hashmap for checking all factors and multiples of a number

Thanks for the help I have used a map but I am not able to find the multiples and then return the array can some one share that code pls

#include <bits/stdc++.h>

using namespace std;

int main()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
map<int,int> m;
for(int i=0;i<n;i++)
{
m[a[i]]++;

}

return 0;

}

Checkout this

baki graph wale hue the kya ??

Can u please elaborate it a little more?

nahi