Help needed for Chef and Numbers

please tell me where i am going wrong.

problem link: RECNDNOS Problem - CodeChef

MY approch is to for each type of dish get indexs of perticular dishtype and increase count if current index is not adjacent to previous index.

``````public class RECNDNOS {
static HashSet<Integer> set = new HashSet<Integer>();
public static void main(String[] args) {
try {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
while(T-- != 0){
int _max = 0;
int count=0;
HashMap<Integer,ArrayList<Integer>> map = new   HashMap<Integer,ArrayList<Integer>>(); // type of dish -> [list of indexes]

for(int i=0;i<N;i++){
if(map.containsKey(arr[i])){
}else{
ArrayList<Integer> tl = new  ArrayList<Integer>();
map.put(arr[i],tl);
}
}
int g_ctr=0;
int ans=-1;
for(Map.Entry<Integer,ArrayList<Integer>> entry : map.entrySet()){  //logic starts here
int key = entry.getKey();
int counter =0;
ArrayList<Integer> tl = entry.getValue();
int prevIdx = -1;
for(Integer e : tl){
if(prevIdx == -1  || e-1 != prevIdx ){  // if previous index is not one step less of current index then count
counter++;
}
prevIdx=e;

}
if(g_ctr<counter){
g_ctr=counter;
ans = key;
}

}
bw.write(ans+"\n");

}

bw.flush();
} catch (Exception e) {
//TODO: handle exception
System.out.println(e);
}
}
static int[] takeInputArray(String str, int len) {
StringTokenizer st = new StringTokenizer(str);
int arr[] = new int[len];
for (int i = 0; i < len; i++) {

arr[i] = parseInt(st.nextToken());