RECNDNOS - Editorial

Please let me know why this is giving me wrong solution

public class RECNDNOS {

    public static void main(String[] args) throws java.lang.Exception {
        try {
            InputReader in = new InputReader(System.in);
            int t = in.nextInt();
            while (t-- > 0) {
                Map<Integer, Integer> keyAndCountMap = new HashMap<>();
                int n = in.nextInt();
                int a[] = Arrays.stream(in.nextLine().split(" ")).map(value -> Integer.parseInt(value)).mapToInt(x -> x).toArray();
                int continousCount = 1;
                for (int i = 0; i < a.length; i++) {
                    while (i < a.length - 1 && a[i] == a[i + 1]) {
                        continousCount += 1;
                        i++;
                    }
                    if (keyAndCountMap.containsKey(a[i])) {
                        int count = keyAndCountMap.get(a[i]);
                        keyAndCountMap.put(a[i], count + continousCount / 2 + continousCount % 2);
                    } else {
                        keyAndCountMap.put(a[i], continousCount / 2 + continousCount % 2);
                    }
                    continousCount = 1;
                }

                int maxKey = 0;
                int maxCount = 0;
                Iterator<Map.Entry<Integer, Integer>> iterator = keyAndCountMap.entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry<Integer, Integer> entry = iterator.next();
                    if (entry.getValue() > maxCount) {
                        maxKey = entry.getKey();
                        maxCount = entry.getValue();
                    }
                }

                System.out.println(maxKey);
            }
        } catch (Exception e) {
            return;
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
}

this program gives correct answer when i copy paste the sample input as custom input but wrong answer when i submit. Can anyone help?
#include <stdio.h>
#include <malloc.h>

int main(void) {
int T=0;//no. of test cases
int* A=0;//array of dishes
int N=0;//no. of items in array
int type=0,pno=0;//to store type and picked no.
int ctype=0,cpno=0;//current type and picked no.

int i,j,t=0;

scanf("%d",&T);
for(t=0;t<T;t++)
{
scanf("%d",&N);
A = (int*) malloc(sizeof(int)*N);
for(i=0;i<N;i++) scanf("%d",&A[i]);//inputting array
for(i=0;i<N;i++)
{
  ctype = A[i];
  for(j=0;j<N-2;j++)
  {
    if( A[j]==ctype && A[j+1]!=ctype ) cpno++;//counting no. of times picked
    if( A[j]==ctype && A[j+2]!=ctype ) cpno++;
  }
 if(cpno>pno)
 {
   pno = cpno;
   type = ctype;
 }
 ctype=0;
 cpno=0;
}
printf("%d\n",type);
}
return 0;

}
// this program gives correct answer when i copy paste the sample input as custom input but wrong answer when i submit

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

Above mentioned link contains my solution attempt. whats wrong with my solution, please help this amateur coder.
Its giving correct output as per me.

MY IDEA.
iterate over i=0 to i=n-1
if(arr[i]==arr[i+1]) arr[i+1]= -1;
Then iterate from i=0 to i<n
if(arr[i]!= -1) count[arr[i]]++;
Then take max;

I THINK YOU UNDERSTAND IT. IF NOT WHAT IS DOUBT;