I had a technical interview and I couldn’t solve the exersice they challenged me with. Can someone please explain how to solve this?
Givan an object of users. Each user can belong to one group or more.
const users = {
1: {
id: 1,
email: '[email protected]',
teams: []
},
2: {
id: 2,
email: '[email protected]',
teams: [1,2]
},
3: {
id: 3,
email: '[email protected]',
teams: [2,4]
},
4: {
id: 4,
email: '[email protected]',
teams: [1,5]
},
}
const msg = {
text: "Hi",
sender: 2,
mentions: {
users: [1,3],
groups: [3,4]
}
}
function sendNotification(text, email) {
console.log(`send email to ${email}`);
}
Write a function that calls sendNotification
fucntion in order to send a message to all the users and the teams mentioned in the msg.mentions
object. You can’t change anything in the given users
object and the sendNotification
functions.
function x(msg) {
// implement your code here.
}
I tried to write a code that goes over the arrays in msg.netions.users
and msg.netions.users
and check for the user’s email and its group, but the time complexity is bad in this approach.
I’ll be happy to hear any suggestion for solving this problem so I could learn from it.
Thank you!