Compute Weighted Post Length With Fixed Link Cost
Last updated: November 29, 2026
Quick Overview
Given the text of a draft post, compute its weighted character length where most Latin characters count 1, CJK and emoji count 2, and every URL counts as exactly 23 regardless of its real length, then report whether it fits the 280 limit.
X
November 29, 20260
0
0 solved
Given the text of a draft post, compute its weighted character length where most Latin characters count 1, CJK and emoji count 2, and every URL counts as exactly 23 regardless of its real length, then report whether it fits the 280 limit.
The compose box on X shows a live counter that does not equal len(text): links are wrapped by the t.co shortener and wide scripts take two slots. A phone screen uses this to check that you can translate a product rule into clean code and think about Unicode instead of assuming ASCII.
What the Interviewer Expects
- Asks how URLs are detected and what counts as one
- Separates URL spans from ordinary text before weighting
- Uses code point ranges for weights rather than hardcoding a few scripts
- Returns both the length and whether it is valid
- Mentions grapheme clusters and emoji ZWJ sequences as a known gap
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 return the index where the post first goes over the limit so the UI can highlight the overflow?
- A family emoji is several code points joined by ZWJ but should count as 2. How do you handle it?
- Premium users get a much higher limit. How would you make the rule configurable per account?
- How do you keep the client and server counters from disagreeing?
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: a string. Output: (weighted_length, is_valid). Rules: a URL (here, anything matching https?:// followed by non-space characters) costs 23 no matter how long it is, because the server rewrit...
High-Level Design
Scan URL matches left to right with a regex. For the text between matches, sum per-character weights; for each match add 23. Keep the weight table as a list of (lo, hi) ranges so product can change ...