Time Limit Exceeded... After Shuffle

where i am wrong in this code

Make a separate function for partition and determining pivot element in your code, your shuffle function is working fine, I have checked it.

by making a separate function for partition how time complexity is reduced???

Your code is not working correct bcz of the logic you have used for determining the pivot element, so its better to make a separate function and use correct logic instead.