Hello, I can point out two mistakes: 1. You should have initialized the ArrayList. 2. You could have done the entire operation using streams. instead of invoking Collections.sort and subList(0,3), you could have done this: List suggestions = new ArrayList(); for (int i=1; i product.startsWith(str.substring(0,finalI))) .sorted() .limit(3) .collect(Collectors.toList()); suggestions.add(list); }
Hello, I can point out two mistakes:
1. You should have initialized the ArrayList.
2. You could have done the entire operation using streams. instead of invoking Collections.sort and subList(0,3), you could have done this:
List suggestions = new ArrayList();
for (int i=1; i product.startsWith(str.substring(0,finalI)))
.sorted()
.limit(3)
.collect(Collectors.toList());
suggestions.add(list);
}
Thanks Sneh for the great suggestions.
@@letsease184 You're welcome 👍
Trie is your friend here