-
Notifications
You must be signed in to change notification settings - Fork 160
/
remove-all-adjacent-duplicates-in-string-ii.md
41 lines (30 loc) · 1.46 KB
/
remove-all-adjacent-duplicates-in-string-ii.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<p>Given a string <code>s</code>, a <em>k</em> <em>duplicate removal</em> consists of choosing <code>k</code> adjacent and equal letters from <code>s</code> and removing them causing the left and the right side of the deleted substring to concatenate together.</p>
<p>We repeatedly make <code>k</code> duplicate removals on <code>s</code> until we no longer can.</p>
<p>Return the final string after all such duplicate removals have been made.</p>
<p>It is guaranteed that the answer is unique.</p>
<p> </p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcd", k = 2
<strong>Output:</strong> "abcd"
<strong>Explanation: </strong>There's nothing to delete.</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> s = "deeedbbcccbdaa", k = 3
<strong>Output:</strong> "aa"
<strong>Explanation:
</strong>First delete "eee" and "ccc", get "ddbbbdaa"
Then delete "bbb", get "dddaa"
Finally delete "ddd", get "aa"</pre>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input:</strong> s = "pbbcggttciiippooaais", k = 2
<strong>Output:</strong> "ps"
</pre>
<p> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= s.length <= 10^5</code></li>
<li><code>2 <= k <= 10^4</code></li>
<li><code>s</code> only contains lower case English letters.</li>
</ul>