Apart from stack of recursion, what is the space complexity here? I think it is average O(logn) and worst O(n). Since each recursion function's pivot and bigger will be kept until all sub-function are done. Correct me if I'm wrong.

your solution is not O(nlogn) in worst case. lets say, there's a tree that each inter node has only right child. Then the time complex will be O(n^2). Please correct if i am wrong.