Partition Labels
You are given a string s of lowercase English letters. Cut it into as many pieces as possible so that every letter appears in at most one piece. Joining the pieces in order must give back s, so a piece is always a contiguous chunk of the string.
Return an array with the length of each piece, from left to right.
Constraints
1 <= s.length <= 500sconsists of lowercase English letters.
Examples
Example 1
Input: s = "abacdcde" Output: [3,4,1]
"aba" holds every a and b, "cdcd" holds every c and d, and the e at the end is alone. Any other cut would split some letter across two pieces.
Example 2
Input: s = "xyzx" Output: [4]
The x at both ends forces the whole string into a single piece.
Example 3
Input: s = "abc" Output: [1,1,1]
No letter repeats, so every letter can be its own piece.
JavaScript you'll use: Strings and characters Map and Set
/**
* @param {string} s
* @return {number[]}
*/
function partitionLabels(s) {
}
Ctrl/⌘ + ' runs the examples, Ctrl/⌘ + Enter submits. Use console.log freely: output shows under Console. In the editor, press Esc then Tab to move focus out.