NewThe Learning module is now liveSee what's new

In a group chat, users can mention one another in message text. A mention starts with the '@' character, followed by one or more comma-separated user IDs with no spaces inside. For example, "@id1" mentions one user, while "@id1,id42,id999" mentions three users. A user ID consists of the prefix id followed by a positive integer from 1 to 999.

A valid mention must appear as its own token: the '@' must be either at the start of the message or immediately after a space, and the mention ends at the next space or at the end of the message. An '@' that appears inside another word, such as "appro@ch", is not a mention and must be ignored. Every '@' token that appears at a valid token boundary is guaranteed to be well-formed.

Given members (an array of known user IDs) and messages (an array of chat message strings), count the number of messages each member is mentioned in.

  • If a member is covered by more than one mention token within the same message, that message is counted only once for that member.
Test Cases
Input
Output
Expected