In the solution #1 the Arrays.sort() function is being called n - 1 times making the overall time complexity n-squared log n O(n2log(n)). It is enough to sort the array once before the for loop. no need to sort the array for every iteration.
Type your question above this line.
Course: https://www.educative.io/collection/10370001/5347133077061632
Lesson: https://www.educative.io/collection/page/10370001/5347133077061632/6332832517455872