These problems are always looking to test. It seamedseemed way to straight forward until I realized the clue.
To be fair in JS a there there is no such thing as a listlist which helps understand the problem.
This is a storage problem
This is a storage problem
Well that is the gist of it. The solution turned out a little more complicated (it was a hard one). But it maintains a storage complexity of \$O(1)\$ and a complexity of \$O(n)\$ (was hoped it could be log(n) but edge cases made it impossible for my mind)
function partition(arr, pivot) {
var i, temp, top = arr.length - 1, mid = 0, step = true;
for (i = 0; i <= top - mid; i++) {
if (mid && step) { arr[i] = arr[i + mid] }
step = true;
if (arr[i] > pivot) {
if (arr[top] === pivot) {
arr[top--] = arr[i];
arr[i] = arr[i + (++mid)];
} else {
temp = arr[i];
arr[i] = arr[top];
arr[top--] = temp;
step = false;
}
i--;
} else if(arr[i] === pivot) {
mid++;
i--;
}
}
while (mid--) { arr[i++] = pivot }
return arr;
}