Hey guys,
Could you please take a look what can be wrong here. I get correct output but still cannot pass the test.
Thanks,
Roman

package com.codegym.task.task18.task1803;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
/*
Most frequent bytes
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String name = reader.readLine();
InputStream input = new FileInputStream(name);
ArrayList<Integer> arr = new ArrayList<Integer>();
while (input.available() > 0) {
int data = input.read();
arr.add(data);
}
input.close();
Collections.sort(arr);
int n = arr.size();
//System.out.println(arr);
mostFrequent(arr, n);
}
public static int mostFrequent(ArrayList<Integer> arr, int n) {
ArrayList<Integer> curr = new ArrayList<Integer>();
int max_count = 1, res = arr.get(0);
int curr_count = 1;
for (int i = 1; i < n; i++) {
if (arr.get(i) == arr.get(i - 1))
curr_count++;
else {
if (curr_count > max_count) {
/*if (curr_count > 1)
curr.add(arr.get(i - 1));*/
//max_count = curr_count;
res = arr.get(i - 1);
}
curr_count = 1;
}
}
// If last element is most frequent
/*if (curr_count > max_count)
{
max_count = curr_count;
res = arr.get(n - 1);
//curr.add(arr.get(n - 1));
}*/
/*for (Integer t : curr) {
System.out.print(t + " ");
}*/
System.out.print(res + " ");
return res;
}
}