Imagine there is a group chat with many users writing messages. The content of messages includes text and mentions of other users in the chat. Mentions in the group chat are formatted as strings starting with @ character and followed by at least one id separated by commas. An id is formatted as a string starting with id and followed by a positive integer from 1 to 999.
Example:
"This is an example with no mentions"
"This is an example with @id1 one mention of one user"
"This is an example with @id1,id2,id3 one mention of three users"
"This is an example with @id1,id1,id2,id3 several mention of several users"
"@id23"
Now, imagine you are given two arrays of strings titled members and messages. Your task is to calculate the mention statistics for the group chat. In other words, count the number of times each member id is mentioned in the messages list. If the same id appears multiple times in a message, it should be counted only once per message.
Return the mention statistics in an array of strings, where each string follows this format:
"[user id]:[mentions count]"
The array should be sorted by mention count in descending order, or in case of a tie, lexicographically by user id in ascending order.
Notes:
- It is guaranteed that proper ids will be used for each mention.
- Additionally, all mentions will be preceded by and followed by a space, unless they are located at either the beginning or end of the message.
Given an empty array that should contain integers numbers, your task is to process a list of queries on it. Specifically, there are two types of queries:
- "+x" – add integer x to numbers, may contain multiple instances of the same integer.
- "-x" – remove a single instance of integer x from numbers.
After processing each query, record the number of pairs in numbers with a difference equal to a given diff. The final output should be an array of such values for all queries.
Notes:
- All numbers in numbers are positive integers.
- It is also guaranteed that if every "-x" query is executed, the specified number x exists in numbers.
- It is guaranteed that the answer for each query fits into a signed 32-bit integer type.
Example:
For queries = ["+4", "+5", "+2", "-4"] and diff = 1, the output should be
solution(queries, diff) = [0, 1, 1, 0].
Explanation:
- Process queries[0] = "+4" and add 4 to numbers, resulting in numbers = [4].
- There are no pairs with diff = 1, so append 0 to the output.
- Process queries[1] = "+5" and add 5 to numbers, resulting in numbers = [4, 5].
- The numbers 4 and 5 have a difference of 1, so append 1 to the output.
- Process queries[2] = "+2" and add 2 to numbers, resulting in numbers = [4, 5, 2].
- The number of pairs with difference 1 remains the same, so append 1 to the output.
- Process queries[3] = "-4" and remove an instance of number 4, resulting in numbers = [5, 2].
- No valid pairs remain, so append 0 to the output.