You get a string s of lowercase letters.
Cut s into as many parts as you can. Return an ArrayBuffer with the size of each part, from left to right.
Each letter may appear in only one part. So if one part has an a, no other part can have one.
The parts keep the letters in order. Put back together, they give s again.
Example 1:
Input: s = "noonlevelradar" Output: [4,5,5] Explanation: The parts are "noon", "level" and "radar". No letter shows up in two of them. A cut inside "noon" would split its two n's.
Example 2:
Input: s = "mississippi" Output: [1,10] Explanation: The parts are "m" and "ississippi". The m appears only once, so it is a part alone. The first i is at index 1, and the last i is the final letter. So "ississippi" can't be cut.
Example 3:
Input: s = "world" Output: [1,1,1,1,1] Explanation: Every letter appears once. So each letter is a part of its own.
Constraints:
shas 1 to 100,000 letters.- Each letter is from a to z.
Note:
Your solution should run in O(n) time.
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
