Segment a message with width-constrained suffixes
Company: TikTok
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
Quick Answer: This question evaluates algorithm design and string-processing skills, focusing on constraint-aware segmentation with variable-length suffix metadata and the accompanying complexity analysis.
Segment Message with Suffix Excluded from Width
Constraints
- W counts only message characters in this part
Examples
Input: ('abcdefghij', 4)
Expected Output: ['abcd1/3', 'efgh2/3', 'ij3/3']
Explanation: Three chunks before suffixes.
Input: ('', 5)
Expected Output: ['1/1']
Explanation: Empty message still produces one empty segment with suffix.
Input: ('abc', 0)
Expected Output: []
Explanation: Impossible width returns empty list.
Hints
- n is known after chunking by W.
Segment Message with Suffix Included in Width
Constraints
- Breaking anywhere is allowed
- Return [] when impossible
Examples
Input: ('abcdefghij', 6)
Expected Output: ['abc1/4', 'def2/4', 'ghi3/4', 'j4/4']
Explanation: Suffix consumes part of width.
Input: ('abc', 3)
Expected Output: []
Explanation: Only one-character payload fits with 1/3 suffixes.
Input: ('abc', 2)
Expected Output: []
Explanation: Width too small for any suffix.
Input: ('', 3)
Expected Output: []
Explanation: Empty message with one suffix.
Hints
- Try increasing n until total payload capacity reaches the message length.