Distinct K

66
0
Home Programs Distinct K

Problem Statement
Ashish is provided with a collection of n strings in which some strings are of repeating nature and he has been given with a number k.His task is to find the kth unique string. Also before finding the kth unique string he has to sort each individual string beforehand. If there are fewer unique strings than k return empty string.As his best friend, your task is to help Ashish in accomplishing the task.

Input Format
The first line contains an integer n denoting the number of strings.
The next n lines contain strings.
The next line contains an integer k.

Output Format
The output contains the kth distinct string.

Constraints
1<=n<=105
-100<=arr[i]<=100

Example Input/Output 1:
Input
3
aaa
aa
a
1
Output
aaa
Explanation
Because all of the strings in arr are unique, the first string “aaa” is returned.


Example Input/Output 2:
Input
6
d
b
c
b
c
a
2
Output
a
Explanation
The only strings in arr that are distinct are “d” and “a.” The letter “d” comes first, making it the first separate string.Because “a” appears second, it is the second distinct string. “a” is returned since k == 2.

a=int(input())
b=[]

#getting input chracter and storeing it in b list
for i in range(a):
  c=input().strip()
  b.append(c)

k=int(input())
f=0

for i in b:
  if b.count(i)==1:
    f+=1
  if f==k:
    print(i)
    break
Hephzibai
WRITTEN BY

Hephzibai

Hephzibai is a driven third-year student at St. Joseph's Institute of Technology, specializing in Computer Science and Engineering. With a keen interest in data science and also in fullstack.
One of my greatest strengths lies in my programming skills, which I've honed through countless hours of practice and participation in coding challenges. Platforms like Skillrack, HackerRank, and others have been my playgrounds, where I've tackled a wide range of problems with creativity and determination.

Leave a Reply

Your email address will not be published. Required fields are marked *