|
| 1 | +<h2><a href="https://leetcode.com/problems/kth-distinct-string-in-an-array/">2053. Kth Distinct String in an Array</a></h2><h3>Easy</h3><hr><div><p>A <strong>distinct string</strong> is a string that is present only <strong>once</strong> in an array.</p> |
| 2 | + |
| 3 | +<p>Given an array of strings <code>arr</code>, and an integer <code>k</code>, return <em>the </em><code>k<sup>th</sup></code><em> <strong>distinct string</strong> present in </em><code>arr</code>. If there are <strong>fewer</strong> than <code>k</code> distinct strings, return <em>an <strong>empty string </strong></em><code>""</code>.</p> |
| 4 | + |
| 5 | +<p>Note that the strings are considered in the <strong>order in which they appear</strong> in the array.</p> |
| 6 | + |
| 7 | +<p> </p> |
| 8 | +<p><strong class="example">Example 1:</strong></p> |
| 9 | + |
| 10 | +<pre><strong>Input:</strong> arr = ["d","b","c","b","c","a"], k = 2 |
| 11 | +<strong>Output:</strong> "a" |
| 12 | +<strong>Explanation:</strong> |
| 13 | +The only distinct strings in arr are "d" and "a". |
| 14 | +"d" appears 1<sup>st</sup>, so it is the 1<sup>st</sup> distinct string. |
| 15 | +"a" appears 2<sup>nd</sup>, so it is the 2<sup>nd</sup> distinct string. |
| 16 | +Since k == 2, "a" is returned. |
| 17 | +</pre> |
| 18 | + |
| 19 | +<p><strong class="example">Example 2:</strong></p> |
| 20 | + |
| 21 | +<pre><strong>Input:</strong> arr = ["aaa","aa","a"], k = 1 |
| 22 | +<strong>Output:</strong> "aaa" |
| 23 | +<strong>Explanation:</strong> |
| 24 | +All strings in arr are distinct, so the 1<sup>st</sup> string "aaa" is returned. |
| 25 | +</pre> |
| 26 | + |
| 27 | +<p><strong class="example">Example 3:</strong></p> |
| 28 | + |
| 29 | +<pre><strong>Input:</strong> arr = ["a","b","a"], k = 3 |
| 30 | +<strong>Output:</strong> "" |
| 31 | +<strong>Explanation:</strong> |
| 32 | +The only distinct string is "b". Since there are fewer than 3 distinct strings, we return an empty string "". |
| 33 | +</pre> |
| 34 | + |
| 35 | +<p> </p> |
| 36 | +<p><strong>Constraints:</strong></p> |
| 37 | + |
| 38 | +<ul> |
| 39 | + <li><code>1 <= k <= arr.length <= 1000</code></li> |
| 40 | + <li><code>1 <= arr[i].length <= 5</code></li> |
| 41 | + <li><code>arr[i]</code> consists of lowercase English letters.</li> |
| 42 | +</ul> |
| 43 | +</div> |
0 commit comments