The output is correct, I checked with three files, and the result is always correct.
But verification is not valid!
package com.codegym.task.task18.task1804;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String filename = reader.readLine();
FileInputStream inputStream = new FileInputStream(filename);
HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
List<Integer> list = new ArrayList<Integer>();
while(inputStream.available() > 0){
int data = inputStream.read();
list.add(data);
for (int i : list){
}
}
inputStream.close();
List<Integer> list2 = new ArrayList<Integer>(list);
for(int i = 0; i < list.size(); i++){
int count = 0;
for(int j = 0; j < list2.size(); j++){
if (list.get(i).equals(list2.get(j))){
count++;
}else{
map.put(list.get(i), count);
}
}
}
Integer min = Integer.MAX_VALUE;
for (Map.Entry<Integer, Integer> param : map.entrySet()){
if (param.getValue() < min){
min = param.getValue();
}
}
for (Map.Entry<Integer, Integer> param : map.entrySet()){
if(param.getValue().equals(min)){
System.out.println(param.getKey() + " ");
}
// System.out.println(param.getKey() + " " + param.getValue());
}
}
}