2053. Kth Distinct String in an Array Easy

@problem@discussion
#Array#Hash Table#String#Counting



1/**
2 * [2053] Kth Distinct String in an Array
3 *
4 * A distinct string is a string that is present only once in an array.
5 * Given an array of strings arr, and an integer k, return the k^th distinct string present in arr. If there are fewer than k distinct strings, return an empty string "".
6 * Note that the strings are considered in the order in which they appear in the array.
7 *  
8 * Example 1:
9 * 
10 * Input: arr = ["d","b","c","b","c","a"], k = 2
11 * Output: "a"
12 * Explanation:
13 * The only distinct strings in arr are "d" and "a".
14 * "d" appears 1^st, so it is the 1^st distinct string.
15 * "a" appears 2^nd, so it is the 2^nd distinct string.
16 * Since k == 2, "a" is returned. 
17 * 
18 * Example 2:
19 * 
20 * Input: arr = ["aaa","aa","a"], k = 1
21 * Output: "aaa"
22 * Explanation:
23 * All strings in arr are distinct, so the 1^st string "aaa" is returned.
24 * 
25 * Example 3:
26 * 
27 * Input: arr = ["a","b","a"], k = 3
28 * Output: ""
29 * Explanation:
30 * The only distinct string is "b". Since there are fewer than 3 distinct strings, we return an empty string "".
31 * 
32 *  
33 * Constraints:
34 * 
35 * 	1 <= k <= arr.length <= 1000
36 * 	1 <= arr[i].length <= 5
37 * 	arr[i] consists of lowercase English letters.
38 * 
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/kth-distinct-string-in-an-array/
43// discuss: https://leetcode.com/problems/kth-distinct-string-in-an-array/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48    pub fn kth_distinct(arr: Vec<String>, k: i32) -> String {
49        String::new()
50    }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57    use super::*;
58
59    #[test]
60    fn test_2053() {
61    }
62}
63


Back
© 2025 bowen.ge All Rights Reserved.