Почему валидатор не принимает? Сам тестировал, всё работает.
package com.javarush.task.task18.task1803;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Collections;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Byte> list = new ArrayList<>();
ArrayList<Byte> listOfMaxes = new ArrayList<>();
int max = 0;
int newMax = 0;
String fileName = reader.readLine();
FileInputStream inputStream = new FileInputStream(fileName);
while (inputStream.available() > 0) {
list.add((byte)inputStream.read());
}
inputStream.close();
Collections.sort(list);
byte firstByte = list.get(0);
for (byte b : list) {
if (b == firstByte) newMax++;
else if (b != firstByte) {
firstByte = b;
if (newMax > max) {
max = newMax;
listOfMaxes.clear();
listOfMaxes.add(b);
} else if (newMax == max) {
listOfMaxes.add(b);
}
newMax = 1;
}
if (b == list.get(list.size() - 1)) {
if (newMax > max) {
listOfMaxes.clear();
listOfMaxes.add(b);
} else if (newMax == max) {
listOfMaxes.add(b);
}
}
}
listOfMaxes.forEach(b -> System.out.print(b + " "));
}
}