Partition Labels
You get a string of lowercase letters. Cut it into as many parts as you can so that each letter appears in only one part, and return the lengths of the parts in order. Our example: "cabcdbefegfh" — the answer is [6, 5, 1]: "cabcdb", "efegf" and "h".
- input
s: a string of lowercase English letters.- returns
- Cut
sinto as many parts as you can so that each letter appears in one part only; return the lengths of the parts, in order. - constraints
- 1 ≤ s.length ≤ 500
- s has lowercase English letters only
- examples
- Open a test in the tests panel: it shows the input and the expected answer.
/**
* @param {string} s
* @return {number[]}
*/
function partitionLabels(s) {
}
Ctrl ↵
format
reset
saved in this browser
Stuck?
See the solution run step by step on our example, then why it works and its complexity.
Next: more greedy problems
The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.