Skip to content
LC-2053 Easy LeetCode

2053. Kth Distinct String in an Array

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 82% Topics: Array, Hash Table, String, Counting
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(n)

import collections


class Solution(object):
    def kthDistinct(self, arr, k):
        """
        :type arr: List[str]
        :type k: int
        :rtype: str
        """
        count = collections.Counter(arr)
        arr = [x for x in arr if count[x] == 1]
        return arr[k-1] if k-1 < len(arr) else ""

Solution from kamyu104/LeetCode-Solutions · MIT