HELP IN MODEFREQ

I gave this thinking the number of elements and the actual elements would be on different lines
numval = (map(int, input()))
val = list(map(int, input().split()))

So does the input provided in codechef comes
5
1 2 3 1 2
or
5 1 2 3 1 2?

Okay. thanks. I’ll check.

sorry my mistake i gave it in the a format that works on c++

nvm urs working my bad

Okay. Any idea where my code is failing?

1
8
1 1 2 4 4 4 4 4
try this once please

o/p should be 1 but its giving 5. Thanks I got the issue.

np :slight_smile:

bruh length of vector b is n not 10

My code is still giving wrong answers… :persevere:
Let me know if you find any mistake?
https://www.codechef.com/viewsolution/37291130

Thanks

u want me to find ur mistake or tell a solution bruh?

from collections import Counter

def find_modes():
case = int(input())
while(case!=0):
numval = (map(int, input()))
val = list(map(int, input().split()))
count = Counter(val)
freq = list(count.values())
c = Counter(freq)
l = c.most_common()
#print(count, end="\n")
#print("most common: ", l)
mode = l[0][0]
for i in range(0,(len(l)-1)):
if(l[i][1] != l[i+1][1]):
mode = l[i][0]
break
else:
if(l[i][1]>l[i+1][1]):
mode = l[i][0]
#print(ā€œmodeā€, mode)

    print(mode)
    case = case - 1

return 0

find_modes()

@code_tec

Look at my solution : CodeChef: Practical coding for everyone

Maybe it will help you !

2 Likes

nice code

Thanks :slightly_smiling_face:

Thanks. It did help.

1 Like

Thank you as well

can you please explain your code

i dont think theres a need to sort the list man…

https://www.codechef.com/viewsolution/37228724

refer my solution if u like…

thanks bro