{"id":"41647283-672a-4f0e-9a15-9d9c4b56883d","name":"Partition Labels","description":"1. A string 's' of lowercase English letters is given. \r\n2. We want to partition this string into as many parts as possible so that each letter appears in at most one part.\r\n3. Return a list of integers representing the size of these parts.\r\n","inputFormat":"s = \"ababcbacadefegdehijhklij\"\r\n","outputFormat":"[9,7,8]\r\nExplanation:\r\nThe partition is \"ababcbaca\", \"defegde\", \"hijhklij\".\r\nThis is a partition so that each letter appears in at most one part.\r\nA partition like \"ababcbacadefegde\", \"hijhklij\" is incorrect, because it splits s into less parts.","constraints":"1. 's' will have length in range [1, 500].\r\n2. 's' will consist of lowercase English letters ('a' to 'z') only.\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nvector<int> partitionLabels(string s) {\n // write your code here\n \n}\n \nint main(){\n string str;\n cin>>str;\n\n vector<int> res = partitionLabels(str);\n for (int val : res) {\n cout<<val<<\" \";\n }\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n // ~~~~~~~~~~~~~~~User Section~~~~~~~~~~~~~~~\r\n public static List<Integer> partitionLabels(String s) {\r\n // write your code here\r\n }\r\n\r\n // ~~~~~~~~~~~~~Input Management~~~~~~~~~~~~~~~\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n String str = scn.nextLine();\r\n\r\n List<Integer> res = partitionLabels(str);\r\n for (int val : res) {\r\n System.out.print(val + \" \");\r\n }\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"ababcbacadefegdehijhklij","sampleOutput":"9 7 8 ","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"35f2cfb0-6f25-4967-b0c9-92f2384b9260","name":"Arrays And Strings For Intermediate","slug":"arrays-and-strings-for-intermediate-732","type":0},{"id":"3dd85e88-1a21-4e0d-9866-2d297ea52251","name":"Partition Labels","slug":"partition-labels","type":1}],"next":{"id":"7a0747c6-9044-45b0-bfc5-2cc093adc64d","name":"Partition Labels","type":3,"slug":"partition-labels"},"prev":{"id":"4fd61329-4025-4cbb-b138-3cabbff0bef3","name":"Product Of Array Except Itself Without Using Division Operator MCQ","type":0,"slug":"product-of-array-except-itself-without-using-division-operator-mcq"}}}

Partition Labels

1. A string 's' of lowercase English letters is given. 2. We want to partition this string into as many parts as possible so that each letter appears in at most one part. 3. Return a list of integers representing the size of these parts.

{"id":"41647283-672a-4f0e-9a15-9d9c4b56883d","name":"Partition Labels","description":"1. A string 's' of lowercase English letters is given. \r\n2. We want to partition this string into as many parts as possible so that each letter appears in at most one part.\r\n3. Return a list of integers representing the size of these parts.\r\n","inputFormat":"s = \"ababcbacadefegdehijhklij\"\r\n","outputFormat":"[9,7,8]\r\nExplanation:\r\nThe partition is \"ababcbaca\", \"defegde\", \"hijhklij\".\r\nThis is a partition so that each letter appears in at most one part.\r\nA partition like \"ababcbacadefegde\", \"hijhklij\" is incorrect, because it splits s into less parts.","constraints":"1. 's' will have length in range [1, 500].\r\n2. 's' will consist of lowercase English letters ('a' to 'z') only.\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nvector<int> partitionLabels(string s) {\n // write your code here\n \n}\n \nint main(){\n string str;\n cin>>str;\n\n vector<int> res = partitionLabels(str);\n for (int val : res) {\n cout<<val<<\" \";\n }\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n // ~~~~~~~~~~~~~~~User Section~~~~~~~~~~~~~~~\r\n public static List<Integer> partitionLabels(String s) {\r\n // write your code here\r\n }\r\n\r\n // ~~~~~~~~~~~~~Input Management~~~~~~~~~~~~~~~\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n String str = scn.nextLine();\r\n\r\n List<Integer> res = partitionLabels(str);\r\n for (int val : res) {\r\n System.out.print(val + \" \");\r\n }\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"ababcbacadefegdehijhklij","sampleOutput":"9 7 8 ","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"35f2cfb0-6f25-4967-b0c9-92f2384b9260","name":"Arrays And Strings For Intermediate","slug":"arrays-and-strings-for-intermediate-732","type":0},{"id":"3dd85e88-1a21-4e0d-9866-2d297ea52251","name":"Partition Labels","slug":"partition-labels","type":1}],"next":{"id":"7a0747c6-9044-45b0-bfc5-2cc093adc64d","name":"Partition Labels","type":3,"slug":"partition-labels"},"prev":{"id":"4fd61329-4025-4cbb-b138-3cabbff0bef3","name":"Product Of Array Except Itself Without Using Division Operator MCQ","type":0,"slug":"product-of-array-except-itself-without-using-division-operator-mcq"}}}
plane

Editor


Loading...

Partition Labels

easy

1. A string 's' of lowercase English letters is given. 2. We want to partition this string into as many parts as possible so that each letter appears in at most one part. 3. Return a list of integers representing the size of these parts.

Constraints

1. 's' will have length in range [1, 500]. 2. 's' will consist of lowercase English letters ('a' to 'z') only.

Format

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

Sample Input

ababcbacadefegdehijhklij

Sample Output

9 7 8

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode