Array Frequency Equals Value

 Coding Problem Keys 

 Array Frequency Equals Value 

 Problem Statement 

The program must accept N integer values and print the values which are equal to the count of their occurrence (in ascending order).
If there is no such value then the program must print -1.

 Input Format 

The first line contains the value of N.
The second line contains the N integer values separated by a space.

 Output Format 

The first line contains the integer values separated by a space.

 Boundary Condition(s) 

1 <= N
 <= 100
1 <= Each integer value <= 100

 Example Input/Output 1 

 Input 

4
2 4 2 3

 Output 

2

 Example Input/Output 2 

 Input 

11
2 1 4 3 4 3 4 5 3 4 6

 Output 

1 3 4

 Max Execution Time Limit: 100 millisecs 

 Solution 

 Programming Language: Python 3 Language 

n=int(input());k=[]
l=list(map(int,input().split()))
for i in l:
    if l.count(i)==i:k.append(i)
print(*sorted(set(k))) if len(k)!=0 else print(-1)

# Published By PKJCODERS

 Alter 

n=int(input())
l=list(input().split())
k=[];s=set(l)
for i in s:
    if(int(i)==l.count(i)):
        k.append(i)
k=sorted(k)
if(len(k)>0): print(*k)
else: print("-1")

# Published By PKJCODERS

 (Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.) 

Comments

Popular Posts

Snakes and Ladders

Difference between a number and it's reverse

Unique Characters

Matrix Diagonal Pattern

Move M Words - End Reverse

String - Special Characters