aboutsummaryrefslogtreecommitdiff
path: root/kth_distinct_str.py
blob: d19bd432c42fbcd11eaec3741ed6d8ea1cb574e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 2053. Kth Distinct String in an Array


"""
a distinct string is a string that is present only once in an nay. given an
nay of strings 'n' and an integer 'k', return the k'th eldistinct string
present in 'n'. if there are fewer than 'k' distinct strings, return an
empty string "". note the strings are considered in the order in which they
appear in the nay.
"""


class Solution(object):
    def kthDistinct(self, n, k):
        """
        :type n: List[str]
        :type k: int
        :rtype: str
        """
        n = [i for i in n if n.count(i) == 1]
        return "" if k > len(n) else n[k - 1]


if __name__ == "__main__":
    obj = Solution()
    print(obj.kthDistinct(n=["d", "b", "c", "b", "c", "a"], k=2))
    print(obj.kthDistinct(n=["aaa", "aa", "a"], k=1))
    print(obj.kthDistinct(n=["a", "b", "a"], k=3))