Help with following problem #tree2

/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
int t,n,h;
Scanner s=new Scanner(System.in);
t=s.nextInt();
while(t-- > 0)
{ h=0;
n=s.nextInt();
int [] arr=new int [n];

        for(int i=0;i<n;i++)
            arr[i]=s.nextInt();
        Arrays.sort(arr);
        
        while(true)
        {
            if(arr[n-1]==0)
            break;
            h++;
            if(arr[0]==arr[n-1])
                break;
                
            for(int i=n-2;i>=0;i--)
            {
                if(arr[i]!=arr[n-1])
                {
                    for(int j=i;j<n;j++)
                        arr[j]=arr[i];
                    break;
                }
            }
            
        }
        System.out.println(h);
	}
    
}

}

I am able to pass a sub-task of 20% with this code but unable to pass 80% task, can anyone please help me to know which condition is not satisfied with this?

problem code tree2

Your code is O(n^2) which wont pass for n <= 10^5.