Quicksort algorithm

Please tell the mistake as I am getting TLE for test-case 0…

The average time complexity of quicksort is O(n log n) while its worst case complexity is still O(n^2). Ironically , the worst case for quicksort is when the entire array is already sorted. In such a case it takes n^2 time and hence you are getting a TLE. To resolve this issue , a modified version of quicksort called the Randomized Quicksort is used.
I suggest you to read about it.
Basically we just randomize the array to prevent the possibility of taking a sorted array and hence prevent its worst case scenario. Implement randomized quicksort and your code will pass.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.