Randomized Quick Sort

I have used Randomized Quick Sort still it is showing TLE in one test case, earlier I used the concept of taking mid as pivot. Please help me with this.

import java.util.*;
public class Main {
public static void main(String args[]) {

 Scanner sc=new Scanner(System.in);
	int n=sc.nextInt();
	
	int[] ar=new int[n];
	for (int i=0; i<n; i++) {
		ar[i]=sc.nextInt();
	}
	
	quickSort(ar, 0, n-1);
	
	for (int i=0; i<n; i++) {
		System.out.print (ar[i]+" ");
	}

}

private static void quickSort(int[] ar, int min, int max) {
	// TODO Auto-generated method stub
	if (min<max) {
		
		int i=min, j=max, temp;
		int p=(int)(Math.random()*(max-min+1))+min;
		int pivot=ar[p];
		while (i<j) {
			while (i<=max && ar[i]<pivot) {
				i++;
			}
			while (j>=min && ar[j]>pivot) {
				j--;
			}
			
			if (i<j) {
				temp=ar[i];
				ar[i]=ar[j];
				ar[j]=temp;
			}
			
			
		}
		
		quickSort(ar, min, i-1);
		quickSort(ar, i+1, max);
	}
	
	return;
	
}

}

see this to tackle the tle

Thank you… my answer got submitted.

if this solves your doubt please mark it as resolved :slight_smile: