124. Letter-bound sections
Medium
An indexing system needs to split a text into consecutive sections. Each letter in the text must appear in at most one section; in other words, if a letter appears in a section, all of its occurrences must be in that same section. Split texto into the greatest possible number of sections that satisfy this rule, and return their sizes in the order they appear in the text.
Example 1
Input: texto = "abacddbe"
Output: [7,1]
Explanation: The first seven letters form one section because all occurrences of each of their letters are contained there; the final letter forms another section.
Example 2
Input: texto = "cabcaefg"
Output: [5,1,1,1]
Explanation: The occurrences of c, a, and b fit within the first five positions; each remaining letter can form its own section.
Constraints
- 1 <= texto.length <= 50000
- `texto` contains only lowercase letters from 'a' to 'z'.
GreedyStringsHash map
Saved in this browser
Caso 1
texto =
"abacddbe"
Expected =
[7,1]
Caso 2
texto =
"cabcaefg"
Expected =
[5,1,1,1]
Run checks these 2 cases. Submit runs all 11, including hidden ones.