Search
⌘K
Get Premium
Leetcode 2516. Take K of Each Character From Left and Right
Given a string of 'a', 'b', 'c' and integer k, compute the minimum number of characters you must take from the ends to collect at least k of each letter (or -1 if any letter appears < k). Key insight: if totals suffice, this reduces to finding the longest contiguous middle substring whose counts of each letter are ≤ total - k, which can be found with a two-pointer/sliding-window scan.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
All Regions
Comments
Hello Interview Premium
Your account is free and you can post anonymously if you choose.