2163. Kth Distinct String in an Array
My accepted Python solution to LeetCode problem 2163, Kth Distinct String in an Array, running in 3ms.
- Difficulty: Easy
- Python
- Runtime 3ms
- Memory 17.4MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 3ms, memory 17.4MB, accepted 2025-12-29.
class Solution:
def kthDistinct(self, arr: List[str], k: int) -> str:
from collections import Counter
cnt = Counter(arr)
distinct = [s for s in arr if cnt[s] == 1]
return distinct[k-1] if k <= len(distinct) else ""