The result is correct and the code gym does not let it pass.
package pl.codegym.task.task18.task1803;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/*
Najczęściej występujące bajty
*/
public class Solution {
public static void main(String[] args) throws Exception {
//wpisanie nazwy pliku z konsoli
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fileName = reader.readLine();
FileInputStream fileInputStream = new FileInputStream(fileName);
//stworzenie listy z WSZYSTKIMI bajtami z listy
ArrayList<Integer> list = new ArrayList<>();
//policzone bajty
HashMap<Integer, Integer>map= new HashMap<>();
//koncowa lista z najwieksza iloscia powtorzonych bajtow
ArrayList<Integer>result=new ArrayList<>();
//zmienna przechowująca max
int max=0;
int key=0;
//odczyt bajtow z pliku
while (fileInputStream.available()>0){
int data = fileInputStream.read();
list.add(data);
}
//zakmniecie strumiena
fileInputStream.close();
//dodanie mapy
map.putAll(couner(list));
//ustalanie max wartosci
for(Map.Entry<Integer, Integer> x : map.entrySet()){
if(x.getValue()>max){
max=x.getValue();
key=x.getKey();
}
}
//usuniecie klucza
map.remove(key);
//dodanie klucza dla max wartosci
result.add(key);
for(Map.Entry<Integer, Integer> y : map.entrySet()){
if(y.getValue()==max){
result.add(y.getKey());
}
}
for(Integer x : result){
System.out.print(x);
System.out.print(" ");
}
}
//metoda dodajaca klucz i wartosc do mapy
public static HashMap<Integer, Integer> couner(ArrayList<Integer>lista){
HashMap<Integer, Integer>map = new HashMap<>();
int count=0;
for(int i=0;i<lista.size();i++){
int currentByte=lista.get(i);
for(int j=0;j<lista.size();j++){
if(currentByte==lista.get(j)){
count+=1;
map.put(currentByte, count);
lista.remove(lista.get(j));
}
}
count=0;
}
return map;
}
}