PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000091. Chia nhãn (Partition Labels)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Chia nhãn (Partition Labels)
Partition Labels
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given a lowercase string , partition it into the maximum number of nonempty contiguous blocks so each distinct letter appears in at most one block. Every position belongs to exactly one block and the original order must be preserved. Output the block lengths from left to right.
Input
The only input line contains the lowercase string .
Output
Print the number of blocks on the first line, followed by their positive lengths in order on the second line.
Subtasks
- Subtask 1 (20 points): ; every character is a lowercase letter
a–z. - Subtask 2 (30 points): ; every character is a lowercase letter
a–z. - Subtask 3 (50 points): ; every character is a lowercase letter
a–z.
Examples
Input
abacdeed
Output
3
3 1 4
Explanation
The letter a spans positions and , producing block aba of length . Letter c forms its own block of length , and the remaining deed forms a block of length . Thus the lengths are .