Подскажите, пожалуйста, почему валидатор может не пропускать? Идея отрабатывает корректно.
public class Solution {
public static void main(String[] args) throws IOException {
ArrayList<String> list = new ArrayList<>();
TreeSet<Integer> list2 = new TreeSet<>();
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int posSmall = 0;
int posBig = 0;
for (int i = 0; i < 10; i++) {
String str = in.readLine();
list.add(str);
list2.add(str.length());
}
for (int i = 0; i < list.size(); i++) {
if (list.get(i).length() == list2.first())
posSmall = list.indexOf(list.get(i));
}
for (int i = 0; i < list.size(); i++) {
if (list.get(i).length() == list2.last())
posBig = list.indexOf(list.get(i));
}
if (posSmall < posBig)
System.out.println(list.get(posSmall));
else if ((posSmall > posBig))
System.out.println(list.get(posBig));
}
}package com.javarush.task.task07.task0712;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.TreeSet;
/*
Самые-самые
*/
public class Solution {
public static void main(String[] args) throws IOException {
ArrayList<String> list = new ArrayList<>();
TreeSet<Integer> list2 = new TreeSet<>();
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int posSmall = 0;
int posBig = 0;
for (int i = 0; i < 10; i++) {
String str = in.readLine();
list.add(str);
list2.add(str.length());
}
for (int i = 0; i < list.size(); i++) {
if (list.get(i).length() == list2.first())
posSmall = list.indexOf(list.get(i));
}
for (int i = 0; i < list.size(); i++) {
if (list.get(i).length() == list2.last())
posBig = list.indexOf(list.get(i));
}
if (posSmall < posBig)
System.out.println(list.get(posSmall));
else if ((posSmall > posBig))
System.out.println(list.get(posBig));
}
}