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.

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.

&nbsp;
Example 1:

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.


Example 2:

Input: s = "eccbbbbdec"
Output: [10]


&nbsp;
Constraints:


	1 &lt;= s.length &lt;= 500
	s consists of lowercase English letters.


class Solution:
    def partitionLabels(self, s: str) -> List[int]:
        d = defaultdict(list)
        for i, char in enumerate(s):
            d[char].append(i)
        nums = []
        
        for v in d.values():
            nums.append([v[0], v[-1]])

        start = nums[0][0]
        maxIndex = nums[0][1]
        ans = []
        for i in range(1, len(nums)):
            if nums[i][0] <= maxIndex:
                maxIndex = max(maxIndex, nums[i][1])
            else:
                ans.append(maxIndex - start + 1)
                start = nums[i][0]
                maxIndex = nums[i][1]
        ans.append(maxIndex - start + 1)
        # print(ans)
        return ans
class Solution {
    public List<Integer> partitionLabels(String s) {
        
    List<Integer>lr=new ArrayList<>();

    HashMap<Character,Boolean>mp=new HashMap<>();

    int count=0;

    for(int i=0;i<s.length();i++){

    if(!mp.containsKey(s.charAt(i))&&s.lastIndexOf(Character.toString(s.charAt(i)))!=i){
        mp.put(s.charAt(i),true);
    }
    else if(mp.containsKey(s.charAt(i))&&s.lastIndexOf(Character.toString(s.charAt(i)))==i){

    mp.remove(s.charAt(i));

    }
    
    if(mp.isEmpty()){
    lr.add(count+1);
    count=0;
    }
    else{
        count++;
    }
    }


    return lr;


    }
}
class Solution {
public:
    vector<int> partitionLabels(string s) {
        unordered_map<char,int>mp;
        // filling impact of character's
        for(int i = 0; i < s.size(); i++){
            char ch = s[i];
            mp[ch] = i;
        }
        // making of result
        vector<int> res;
        int prev = -1;
        int maxi = 0;

        for(int i = 0; i < s.size(); i++){
            maxi = max(maxi, mp[s[i]]);
            if(maxi == i){
                // partition time
                res.push_back(maxi - prev);
                prev = maxi;
            }
        }
        return res;
    }
};
var partitionLabels = function(s) {
    let last = 0, first = 0;

    let arr = [...new Set(s)], ss = [];
    let temp = '';

    first = s.indexOf(arr[0]);
    last = s.lastIndexOf(arr[0]);

    for(let i = 1; i<arr.length; i++){
        if(s.indexOf(arr[i]) < last){
            if(last < s.lastIndexOf(arr[i])){
            last = s.lastIndexOf(arr[i]);
            }
        }
        else{
            temp = s.slice(first,last+1);
            ss.push(temp.length);
            first = s.indexOf(arr[i]);
            last = s.lastIndexOf(arr[i]);
        }
    }

    temp = s.slice(first,last+1);
    ss.push(temp.length);
    return ss;
};
Partition Labels