Help Me.. getting wrong answer

please help me …

getting wrong answer. please tell me the fault in my code…

Question link:-

Code link:-
http://www.codechef.com/viewsolution/5967320

I see you have used an algorithm with O(testcases* n^2) complexity. For large n, your code is going to give TLE. I’ll suggest this approach: make an array count of 1000 elements and initialize with zero Then as u read elements u can update it as count[input]:=count[input]+1 and then get the maximum :slight_smile: . In this case even if you have various elements of same count . u will get to print smallest one :slight_smile:

The algorithm will go as follows:

 1. read t
 2. for i:=1 to t do
 3.    read n
 4.    initialize count woth zero
 5.    for j:=1 to n do
 6.       read tmp
 7.       count[tmp]:=count[tmp]+1;
 8.    endfor
 9.    max:=-1
 10.   for j:=1 to n do
 11.      if(count[j]>max) do
 12.        max:=count[j]
 13.        maxindex=j
 14.      endif
 15.   endfor
 16.   print maxindex" "max
 17. endfor
 18.end

You can see my code here.