Skip to content

Commit 3f7641d

Browse files
committed
Create README - LeetHub
1 parent 8fc43af commit 3f7641d

File tree

1 file changed

+32
-0
lines changed
  • 2516-take-k-of-each-character-from-left-and-right

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<h2><a href="https://leetcode.com/problems/take-k-of-each-character-from-left-and-right/">2516. Take K of Each Character From Left and Right</a></h2><h3>Medium</h3><hr><div><p>You are given a string <code>s</code> consisting of the characters <code>'a'</code>, <code>'b'</code>, and <code>'c'</code> and a non-negative integer <code>k</code>. Each minute, you may take either the <strong>leftmost</strong> character of <code>s</code>, or the <strong>rightmost</strong> character of <code>s</code>.</p>
2+
3+
<p>Return<em> the <strong>minimum</strong> number of minutes needed for you to take <strong>at least</strong> </em><code>k</code><em> of each character, or return </em><code>-1</code><em> if it is not possible to take </em><code>k</code><em> of each character.</em></p>
4+
5+
<p>&nbsp;</p>
6+
<p><strong class="example">Example 1:</strong></p>
7+
8+
<pre><strong>Input:</strong> s = "aabaaaacaabc", k = 2
9+
<strong>Output:</strong> 8
10+
<strong>Explanation:</strong>
11+
Take three characters from the left of s. You now have two 'a' characters, and one 'b' character.
12+
Take five characters from the right of s. You now have four 'a' characters, two 'b' characters, and two 'c' characters.
13+
A total of 3 + 5 = 8 minutes is needed.
14+
It can be proven that 8 is the minimum number of minutes needed.
15+
</pre>
16+
17+
<p><strong class="example">Example 2:</strong></p>
18+
19+
<pre><strong>Input:</strong> s = "a", k = 1
20+
<strong>Output:</strong> -1
21+
<strong>Explanation:</strong> It is not possible to take one 'b' or 'c' so return -1.
22+
</pre>
23+
24+
<p>&nbsp;</p>
25+
<p><strong>Constraints:</strong></p>
26+
27+
<ul>
28+
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
29+
<li><code>s</code> consists of only the letters <code>'a'</code>, <code>'b'</code>, and <code>'c'</code>.</li>
30+
<li><code>0 &lt;= k &lt;= s.length</code></li>
31+
</ul>
32+
</div>

0 commit comments

Comments
 (0)