FastPrepCount User Mentions in Chat Messages
Problems/Count User Mentions in Chat Messages

Count User Mentions in Chat Messages

Ramp logoRamp● EasyINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Ramp gave this as the first of two questions in a fall 2026 software engineering intern online assessment. The candidate had to work out, for each user, how many chat messages @-mention them, where one @ can name several ids joined by commas and a user counts at most once per message, and then list the users from most to fewest mentions, breaking ties by id.

The report did not give the message format beyond the @ rule, the output format, or any limits. We chose these: a message is words and mention tokens separated by single spaces. Words and ids use only lowercase letters and digits, and ids are 1 to 8 characters. Each result is written as id=count. Ties are broken by plain string order of the ids. Users who are never mentioned are left out, so the answer is empty when nobody is mentioned. There are 1 to 1000 messages of 1 to 100 characters.

Our version is about 85% the same as the reported question.

You are given the chat messages of a team as an array messages. Each message is a list of tokens separated by single spaces. A token that starts with @ is a mention: the @ is followed by one or more user ids separated by commas, so the token "@ann,bob" mentions both ann and bob. Every other token is an ordinary word.

For every user who is mentioned at least once, count how many messages mention them. If one message mentions the same user more than once, in the same token or in different tokens, it still adds only 1 to that user's count.

Return the counts as strings of the form "id=count", sorted by count from highest to lowest. Users with the same count are sorted by id in ascending lexicographic (dictionary) order. Users who are never mentioned do not appear, so if nobody is mentioned, return an empty array.

Function

countMentions(messages: String[]) → String[]

Examples

Example 1

messages = ["hi @ann,bob lunch at noon","@bob can you review","thanks @carl @bob"]return = ["bob=3","ann=1","carl=1"]
  • Message 1 mentions ann and bob with one @.
  • Message 2 mentions bob; message 3 mentions carl and bob.
  • bob is mentioned in 3 messages, ann and carl in 1 each. The tie between ann and carl is broken by id, so ann comes first.

Example 2

messages = ["@dev1,dev2,dev1 ping @dev2","@dev2 done"]return = ["dev2=2","dev1=1"]
  • Message 1 names dev1 twice and dev2 twice, but each user counts once per message.
  • Message 2 mentions dev2 again, so dev2 has 2 and dev1 has 1.

Example 3

messages = ["no mentions here","just text"]return = []
  • No message has a token that starts with @, so nobody is mentioned and the result is empty.

Constraints

  • 1 <= messages.length <= 1000
  • 1 <= messages[i].length <= 100
  • Each message is a list of tokens separated by single spaces, with no space at the start or the end.
  • A word token is one or more lowercase English letters or digits.
  • A mention token is @ followed by one or more user ids separated by single commas, with no empty id.
  • Every user id is 1 to 8 lowercase English letters or digits.

More Ramp interview questions

  • Count Overlapping Square PairsOA · Seen Nov 2026
  • Accept or Decline QueriesOA · Seen Sep 2026
  • Recipe Management SystemOA · Seen Mar 2026
  • Task Manager with Timed AssignmentsOA · Seen Jan 2026
  • Bank Requests with Delayed CashbackOA · Seen Dec 2025
  • Convert Snake Case Variables to Camel CaseOA · Seen Apr 2025
  • Correct Apartment Bedroom CountsOA · Seen Feb 2025
  • Retryable URL MazePHONE SCREEN · Seen Oct 2026
  • Detect Recurring Transactions with Tunable TolerancesONSITE INTERVIEW · Seen Jul 2026
  • Find a User’s Airport from Flight HistoryPHONE SCREEN · Seen Sep 2025

Similar questions at other companies

  • Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
  • Frequently Bought TogetherAmazon · OA
  • Aggregate Paginated Project Run RecordsReplit · OA
  • Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
  • Convert an Entry List to a MapEPAM · PHONE SCREENEPAM interview questions
  • Filter Anagrams of a TargetMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Deduplicate Logs: Keep FirstGoogle · ONSITE INTERVIEWGoogle interview questions
  • Remove Later Anagrams From a ListBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Most Voted CandidateExpedia · ONSITE INTERVIEWExpedia interview questions

Ramp interview experiences

  • Ramp AI Coding Round, Experienced SWE Onsite: 3 Experiences
  • Ramp SWE New Grad OA and Phone Screen: 7 Experiences
  • Ramp Mobile and Android Interview Questions: 6 Experiences
All Ramp interview questionsSee Ramp hiring insights
Saved
class Solution {
    public String[] countMentions(String[] messages) {
        // Write your code here.
    }
}
Checking account…