Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

192. Partition Labels

MediumDay 57 of 60Greedy & Intervals

Given a string s, split it into as many pieces as possible so that each letter appears in at most one piece. Joining the pieces in order must give back s. Return a list with the length of each piece, in order.

Example 1
Input: s = "ababcbacadefegdehijhklij"
Output: [9,7,8]
The pieces are "ababcbaca", "defegde" and "hijhklij".
Example 2
Input: s = "eccbbbbdec"
Output: [10]
Constraints
  • 1 <= s.length <= 500
  • `s` has only lowercase English letters
Hints
Frequently asked at: Amazon, Meta, Google
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min