partitioning solution with kth element in an array problem