Render Slack Message Tokens Into Readable Mentions

Last updated: November 29, 2026

Quick Overview

Slack stores message text with encoded tokens like <@U123>, <#C456|general> and <!here>. Write a function that converts a raw message into display text using lookup maps of user IDs and channel IDs to current names.

Slack
Coding & Algorithms
Software Engineer
Slack
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Slack stores message text with encoded tokens like <@U123>, <#C456|general> and <!here>. Write a function that converts a raw message into display text using lookup maps of user IDs and channel IDs to current names.

A warm-up in the style of Slack's phone screens, grounded in how the platform actually stores mentions so that renames do not break old messages. The interviewer is checking clean single-pass string parsing, sensible fallbacks for unknown IDs, and whether you ask about escaping.

What the Interviewer Expects
  • Parse the text in one linear pass rather than repeated regex replacement on the output
  • Handle user, channel, special broadcast and link tokens distinctly
  • Fall back to the embedded label or a placeholder when an ID is missing from the map
  • Treat an unmatched '<' as literal text
  • State time and space complexity clearly
Key Topics to Cover
String parsing
Tokenization
Hash map lookup
Slack mrkdwn format
Defensive defaults
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Slack escapes literal '<', '>' and '&' as HTML entities; where would you unescape, and why after tokenizing?
  • How would you render a user who has been deactivated or a channel the viewer cannot see?
  • How would you produce rich output (spans with click targets) instead of plain text?
  • How would you go the other way and encode a typed '@ana' into a token at send time?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: raw text, users: {id: display_name}, channels: {id: name}. Tokens look like <@U1>, <@U1|label>, <#C9|general>, <!here>, <https://x|text>. Output plain display text. Unknown user I...

High-Level Design

Walk the string with an index. Copy plain runs up to the next <. On <, find the matching >; if none exists, the rest is literal. Split the token body on the first | into a reference and an opt...


Submit Your Answer
Markdown supported

Related Questions