Split a Comment Into the Most Parts Where Each Letter Stays Local
Last updated: November 29, 2026
Quick Overview
Given a lowercase string, split it into as many contiguous parts as possible so that every letter appears in at most one part. Return the list of part lengths.
Meta
November 29, 20260
0
0 solved
Given a lowercase string, split it into as many contiguous parts as possible so that every letter appears in at most one part. Return the list of part lengths.
A greedy string-as-intervals problem in the style of a Meta phone screen, loosely framed as chunking a comment for parallel moderation where each character class must be handled by one worker. The interviewer checks that you see each letter as an interval from its first to last occurrence and that the answer is merging those intervals.
What the Interviewer Expects
- Records the last index of each character in one pass
- Extends the current part's end to the max last index seen
- Cuts when the scan index reaches the current end
- Explains the equivalence to merging first-to-last intervals
- Returns lengths in order
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
- What if the alphabet is Unicode instead of 26 letters?
- How would you return the parts themselves?
- What if the goal were the fewest parts with each under a max length?
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: lowercase string s, length up to 500 or more. Output: list of lengths of parts, in order, maximizing the number of parts with no letter shared between parts....
High-Level Design
A part that contains a letter must also contain that letter's last occurrence. So scan left to right keeping end, the farthest last occurrence of any letter in the current part. When the scan index ...