finally I got the right result but not accepted :( public class Solution { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); ArrayList<String> list = new ArrayList<String>(); for(int i =0; i < 10; i++) { String s = reader.readLine(); list.add(s); } int strLength = list.get(0).length(); int strIndex = 0; for(int i = 0; i < list.size(); i++) { if(list.get(i).length() < list.get(i+1).length()) { strIndex = i++; System.out.println(strIndex-1); break; } } } }