236. Partition Labels (Count)

MediumStringString

Given a string s, partition it into as many parts as possible so that each letter appears in at most one part. Return the number of such parts.

Input: A quoted string s.

Output: Integer — number of partitions.

Examples

Example 1
Input: "ababcbacadefegdehijhklij"
Output: 3
Explanation: Parts of sizes 9,7,8.
Example 2
Input: "eccbbbbdec"
Output: 1
Explanation: All in one part.
Example 3
Input: "abc"
Output: 3
Explanation: Each letter its own part.

Constraints

Asked by

AmazonInfosysMicrosoftGoogleBloombergMeta
Solve this problem in the editor →