not sure why this gives me an infinite loop error. I run it locally in IntelliJ as well as here and it gives me the correct answer each time. Validation fails and it says "looks like you have an infinite loop"... I don't see how since the code finishes and exits each time.
package com.codegym.task.task07.task0718;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Checking the order
*/
public class Solution {
public static void main(String[] args) throws IOException {
//write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> origList = new ArrayList<>();
ArrayList<String> listCopy = new ArrayList<>();
ArrayList<String> ordered = new ArrayList<>();
String s;
int lowest = 0;
for (int i = 0; i < 10; i++) {
s = reader.readLine();
origList.add(s);
listCopy.add(s);
}
while (listCopy.size() > 0) {
for (int i = 1; i < listCopy.size(); i++) {
if (listCopy.get(lowest).length() > listCopy.get(i).length()) {
//System.out.println("is "+ listCopy.get(lowest).length() + " > "+ listCopy.get(i).length() + " ? if so, lowest = " + listCopy.get(i));
lowest = i;
}
}
//System.out.println("Smallest word this loop = " + listCopy.get(lowest));
ordered.add(listCopy.get(lowest));
listCopy.remove(lowest);
lowest = 0;
}
for (int i=0; i<ordered.size(); i++)
if (!origList.get(i).equals(ordered.get(i))) {
System.out.println(origList.get(i));
break;
}
}
}