Render Bracketed Emoji Shortcodes in Chat Messages
Last updated: November 29, 2026
Quick Overview
Chat messages store emoji as shortcodes like [Smile]; write a function that replaces every known shortcode with its emoji character while leaving unknown codes, stray brackets and unclosed codes exactly as typed.
Tencent
November 29, 20260
0
0 solved
Chat messages store emoji as shortcodes like [Smile]; write a function that replaces every known shortcode with its emoji character while leaving unknown codes, stray brackets and unclosed codes exactly as typed.
WeChat and QQ both encode their built-in sticker set as bracketed text tokens so messages stay plain text across clients and versions. This is a quick screen for client or frontend engineers: the interviewer checks linear-time string scanning and careful handling of messy user input rather than a fragile regex.
What the Interviewer Expects
- Scans the string once in linear time
- Only replaces names present in the map
- Leaves unknown codes and unmatched brackets untouched
- Handles nested or doubled brackets like [[Smile] sensibly
- Mentions the regex alternative and its trade-offs
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you support localized names, so [微笑] and [Smile] map to the same emoji?
- How would you let a user type a literal [Smile] without it rendering?
- How would you render this into rich text nodes for a React or native view instead of a string?
- What if the map has thousands of entries and shortcodes can be long?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: message text and a dict from shortcode name to emoji. Output: text with each [Name] replaced when Name is in the dict. Unknown [Foo] stays literal, [Smile without a closing bracket stay...
High-Level Design
Walk the string with an index. Copy plain runs up to the next [. At a [, find the next ]. If there is none, copy the rest. Otherwise use the innermost [ before that ] as the true start (...