Your Dashboard
Interview Coaching
Learn
System Design
ML System Design
Code
Behavioral
Salary Negotiation
Interview Guides
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.