HackerEarth - Repeated K Times Solution
1 min read

HackerEarth - Repeated K Times Solution

HackerEarth - Repeated K Times Solution

Given a List of N number a1,a2,a3........an, You have to find the smallest number from the List that is repeated in the List exactly K number of times.

Input Format

First Line of Input Contain Single Value N, Size of List

Second Line of Input Contain N Space Separated Integers

Third Line of Input Contain Single Value K

Output Format

Smallest Integer Value That is Repeated Exactly K Number of Time

Constraints

  • 0 < N < 100001
  • 0 <= K < 100001
  • 0 <= ai < 100001

NOTE

There Will Be Atleast One Variable Which Is Repeated K Times

SAMPLE INPUT

5
2 2 1 3 1
2

SAMPLE OUTPUT

1

Solution in Python

from collections import Counter
n = int(input())
a = list(map(int,input().split()))
k = int(input())
c = Counter(a)
print(min(filter(lambda x:x[1]==k,c.items()))[0])

Enjoying these posts? Subscribe for more


Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

That's okay. But without advertising-income, we can't keep making this site awesome.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add thepoorcoder.com to your ad blocking whitelist or disable your adblocking software.

×