LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 3ms, memory 17.4MB, accepted 2025-12-29.

python
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 ""

Source