Your code has a fundamental flaw, which increases the possibility of the list named more
being same in two subsequent iterations. Possible issues lie in the below section of the code:
int pivotIndex = arr.size() / 2;
int pivot = arr.get(pivotIndex);
for (int n : arr) {
if (n < pivot) {
less.add(n);
}
else {
more.add(n);
}
}
Do not add the pivot in the more
or less
list. Moreover, you can understand how to choose the variant here on the blog