Files
cpp-flashcards/org/study_deck_02/dsa/greedy/0763-partition-labels.org
T

59 lines
1.4 KiB
Org Mode
Raw Normal View History

#+PROPERTY: STUDY_DECK_02
* TODO 0763. Partition Labels :medium:
:PROPERTIES:
:NEETCODE: [[file:../../roadmap.org::*0763. Partition Labels][0763. Partition Labels]]
:END:
You are given a string ~s~. We want to partition the string into as many parts as possible so that each letter appears in at most one part. For example, the string ~"ababcc"~ can be partitioned into ~["abab", "cc"]~, but partitions such as ~["aba", "bcc"]~ or ~["ab", "ab", "cc"]~ are invalid.
Note that the partition is done so that after concatenating all the parts in order, the resultant string should be ~s~.
Return /a list of integers representing the size of these parts/.
*Example 1:*
#+begin_src
Input: s = "ababcbacadefegdehijhklij"
Output: [9,7,8]
Explanation:
The partition is "ababcbaca", "defegde", "hijhklij".
This is a partition so that each letter appears in at most one part.
A partition like "ababcbacadefegde", "hijhklij" is incorrect, because it splits s into less parts.
#+end_src
*Example 2:*
#+begin_src
Input: s = "eccbbbbdec"
Output: [10]
#+end_src
*Constraints:*
- ~1 <= s.length <= 500~
- ~s~ consists of lowercase English letters.
** TODO Approach
Write your approach here.
** TODO Python
#+begin_src python
class Solution:
def partitionLabels(self, s: str) -> List[int]:
#+end_src
** TODO C++
#+begin_src cpp
class Solution {
public:
vector<int> partitionLabels(string s) {
}
};
#+end_src