DIY: Partition Labels
Solve the interview question "Partition Labels" yourself in this lesson.
We'll cover the following
Problem statement
You are given a string, s
, of lowercase English letters. We want to partition this string into as many parts as possible such that each letter appears in at most one part. Return an array of integers representing the size of these parts.
Input
The input will contain a string called s
. The following is an example input:
"caedbdedda"
Output
The output will be an array of integers representing the size of partitions created from the string s
. For the above input, the output will be:
[1,9]
The partition will be "c"
and "caedbdedda"
.
Coding exercise
Implement the partitionLabels(s)
function, where s
is the string. The function returns an array of integers representing the size of partitions created from the string s
.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.