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
Coding & Algorithms
Frontend Engineer
Tencent
November 29, 2026
Frontend Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
String parsing
Two pointers
Hash map lookup
Input robustness
Linear time
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
  • 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 Problems
Sample 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 (...


Submit Your Answer
Markdown supported

Related Questions