Practice Take K of Each Character From Left and Right
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Take K of Each Character From Left and Right
Problem Statement
You are given a string s consisting of the characters 'a', 'b', and 'c' and a non-negative integer k. Each minute, you may take either the leftmost character of s, or the rightmost character of s. Return the minimum number of minutes needed for you to take at least k of each character, or return -1 if it is not possible to take k of each character.
Source: Take K of Each Character From Left and Right on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
s = "aabaaaacaabc", k = 2
8
# Example 2
s = "a", k = 1
-1
Constraints
Related LeetCode Problems
Practice more problems similar to Take K of Each Character From Left and Right.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.